Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I improve the performance of my .gif GUI with 70 images (1 frame per 0.04 second)?

This is a section of the script, altogether there's 70 images. At the moment the images keeps on flashing because of latency, it also freezes and then plays perfectly for a split second and then flashes again. Is there anyway I can make it so the images change without flashing?

while true do
	wait(0.04)
	script.Parent.Image = "rbxassetid://544664857"--0
	wait(0.04)
	script.Parent.Image = "rbxassetid://544665861"--1
	wait(0.04)
	script.Parent.Image = "rbxassetid://544666597"--2
end

Here's the place with the .gif GUI: https://www.roblox.com/games/544685431/Seraines-Place-Number-40

Thanks

1 answer

wait() isn't very precise, especially with very short times. You need to use a delta time loop to handle this.

Additionally, the only way to combat the latency is to script this using a LocalScript.

local frames = {
	{img = 544664857, rate = .04};
	{img = 544665861, rate = .04};
	{img = 544666597, rate = .04};
}

--EDIT - yep, I forgot to have the images preloaded! Let's fix that here:
do
	local ContentProvider = game:GetService("ContentProvider")
	local images = {}
	for _, v in ipairs(frames) do
		table.insert(images, "rbxassetid://" .. v.img)
	end
	ContentProvider:PreloadAsync(images)
end
--

local GUI = script.Parent

local RenderStepped = game:GetService("RunService").RenderStepped
local i = 1
local extra = 0
while true do
	GUI.Image = "rbxassetid://" .. frames[i].img
	local st = tick() + extra

	while true do
		RenderStepped:wait()
		local t = tick()
		if t - st >= frames[i].rate then
			extra = t - st - frames[i].rate
			break
		end	
	end

	i = (i + 1)%(#frames + 1)
end

Delta time usage is a confusing concept to understand, so definitely ask any questions you have about it!

Some references that may be helpful:

3 comments

1

You forgot to account for the fact that the frames aren't preloaded.

0

Yeah the gif doesn't play ;c

0

Thanks for you help, but the loop stops after every frame has been played, you can see it here: https://www.roblox.com/games/544685431/Seraines-Place-Number-40

This discussion is preserved as it was. New answers, comments, and votes are closed.