ood evening. I want to write a script to randomize the texture of a 3D model (MeshInnstance) in Godot 4 using Spritesheet (each texture is 18 by 18 pixels in size, the width of the image with textures is 54, with a height of 18 pixels).

@onready var Material_texture_block = $"../Куб"  
@onready var Random_texture_block = $"."
var frames: int
func _ready() -> void:
  frames = int(texture.get_width() / region_rect.size.x)
  var random_index = randi_range(0, frames - 1)
  region_rect.position.x = float(random_index * region_rect.size.x)
  if Material_texture_block == null:
    return
    var material = Material_texture_block.get_surface_override_material(0)
  if material == null:
    material = StandardMaterial3D.new()  Material_texture_block.set_surface_override_material(0, material)
  if material is StandardMaterial3D:
    var image = texture.get_image()
    var cropped_image = Image.new()     cropped_image.copy_from(image) 
    var crop_rect = Rect2i(    int(region_rect.position.x),  int(region_rect.position.y),  int(region_rect.size.x),    int(region_rect.size.y)
    )
cropped_image.crop(crop_rect)
    var new_texture = ImageTexture.create_from_image(cropped_image)  
  material.albedo_texture = new_texture

At the moment, the previous texture image remains unchanged and does not change. How can I fix the script so that it works correctly?