Longer gifs with better quality?

I found a great script by @HungryFox02 and it works great. (Gifs in Roblox with only 1 image) The script:


However, I noticed that the more frames, the worse quality, since the script sizes the image up pretty much. So I had this idea where I could have the script continue looping, but each time it reaches the end to be set to a new texture, perfectly on the last frame. That way, it could be way longer, and also it could be better quality. Problem is, I’m not a scripter, and I have 0 clue how to do this. I’ve already tried to see if I could just make it detect if it’s on the last frame by detecting what number the offset is on, but I don’t know how to make it detect two things at the same time (OffsetStudsU and OffsetStudsV). I couldn’t find anyone else with the same idea either, so I’m not sure if this has already been tried and just doesn’t work or what. I really need help because I’m completely lost here, and I don’t really want to try another method of gifs, but I might have to if it really just doesn’t work like how I think it should.

in my original script, i have a current frame value, you can just do something along the lines of

if CurrentFrame > Gif1Frames then
     -- switch textures here
     -- reset offset here
end

I think I’ve either misunderstood you, or just got way off. It DOES execute the code on the last frame, but everything else doesn’t work. It puts the texture into the gif, but nothing appears at all. Also, when I manually put the texture in while in testing mode, the offset isn’t right either. I think I got this way off. Here’s what the script looks like:

-- Script by HungryBoy02
local Frames = 31 --Amount of frames in gif
local currentFrame = 1

local rows = 7
local columns = 5

local currentRow,CurrentColumn = 0,0

local linear = false

local fps = 5 -- Max 30
local full60fps = false

local size = script.Parent.Parent.Size -- The gif should be on the front of the part

script.Parent.StudsPerTileU = columns*size.X
script.Parent.StudsPerTileV = rows*size.Y

while true do
	if not full60fps then wait(1/fps) else game:GetService("RunService").Stepped:Wait() end
	if linear then
		script.Parent.OffsetStudsU = script.Parent.OffsetStudsU + size.X
		if script.Parent.OffsetStudsU > script.Parent.StudsPerTileU then
			script.Parent.OffsetStudsU = 0
		end
	else
		CurrentColumn = CurrentColumn + 1
		if CurrentColumn > columns then
			CurrentColumn = 1
			currentRow = currentRow + 1
		end
		if currentFrame > Frames then
			currentRow,CurrentColumn,currentFrame = 1,1,1
		end
		script.Parent.OffsetStudsU = size.X*(CurrentColumn-1)
		script.Parent.OffsetStudsV = size.Y*(currentRow-1)
		currentFrame = currentFrame+1
		
		if currentFrame > Frames then
			
			script.Parent.Texture = ("http://www.roblox.com/asset/?id=2632484471") -- switch textures here
			columns = 6
			rows = 9
			Frames = 50
			script.Parent.OffsetStudsU = 0
			script.Parent.OffsetStudsV = 0 -- reset offset here
		end
	end
end

You’d want to have additional parameters for the 2nd gif too and kind of switch between them at the end of the frames for one, sorry my explanation isn’t the greatest here (never been particularly good at it) but aside from remaking the script myself specifically for this, I can’t really explain it better,