I need help on the script of this GIF

Hey, I know how to upload and make GIFS. The only problem is that when I convert to a spritesheet, it comes out with another column but with a little number of images, rather than filling the rest of the row. So on the script, I don’t know how to include the last image(s) on the new column.

Here is the spritesheet of the GIF:

  1. What do you want to achieve? I want the script on the GUI to work without looking like a old theater.

  2. What is the issue? I don’t know how to add in the script the last image(s) on the bottom left

  3. What solutions have you tried so far? I don’t want to lower the speed of the GIF many times, this is the best quality and speed I can get it to with the editor without having frame and quality drops. So I dont know any other solution

Here is the script:

local framesX = 8
local framesY = 4
local frame = 1
script.Parent.ImageLabel.Size = UDim2.new(framesX, 0, framesY, 0)
local maxFrames = framesX*framesY
local frameX = 0
local frameY = 0
local fps = 30

while wait(1/fps) do
	frameX = frameX + 1
	frame = frame + 1
	if frameX > framesX  - 1  then
		frameX = 0
		frameY = frameY + 1
	end
	if frameY > framesY - 1 then
		frame = 0
		frameX = 0
		frameY = 0
	end
	if frame > maxFrames then
		frame = 0
	end
	script.Parent.ImageLabel.Position = UDim2.new(-frameX, 0, -frameY, 0)
end

Replace this with:

if frame > maxFrames and frame < maxFrames + 2 then
		frame = 0
end

edit: Also change the maxFrames thing:

local maxFrames = framesX*(framesY-1)