✓ Accepted answer
I will only give you some tips.
- Instead of using wait(0.05), use wait(). Since wait() is 1/30 of a second. It's the same speed that frames in a movie theater run at.
- Do not use while loops, use RunService instead.
- Don't use inpairs, you'll see what I do.
Wait()
Wait() runs at 1/30th of a second. The same speed movie's frames change at. It would make the Gif run more smoothly.
print(wait())
print(wait(0.05))
Fun Facts about Wait
- Like you did in your script, instead of doing while true do wait(), do while wait() do. Shortcut!
While Loops and RunService
While loops will add lag, do not use them. Instead, use the Heartbeat event in the RunService.
while wait() do
print("SPAM")
end
game:GetService("RunService").Heartbeat:connect(function()
print("SPAM")
end)
Fun Facts about While Loops and RunService
- While loops cause lag! RunService does not.
- There is an event in RunService named RenderStepped. This is 2x faster than wait()! It can only be accessed with a LOCAL SCRIPT. Using this for your gif will make your gif run 2x faster, which isn't normally good...
In Pairs
In this script, in pairs is not necessary. Do this instead:
local frame = 1
script.Parent.Image = "http://www.roblox.com/asset/?id="..frames[frame]
frame = frame+1
Fun Facts about In Pairs
- Instead of In Pairs, some people use
next. But In Pairs should be used instead of Next.
Final Product
Frames = {251495903,251495914,251495930,251495944,251495974}
local frame = 1
game:GetService("RunService").Heartbeat:connect(function()
script.Parent.Image = "http://www.roblox.com/asset/?id="..Frames[frame]
frame = frame+1
if frame > #Frames then
frame = 1
end
end)
Hope this helps!
Extra
- Use the preloader so all the gif get loaded so they aren't black.
game:GetService("ContentProvider"):Preload("http://www.roblox.com/asset/?id="..Frames[frame])
4 comments
Please tell us the issue that you are having. Also, you may want to preload the image assets, otherwise they won't show up until the game has fully loaded.
I changed the question and the explanation to what is supposed to be clear. Now you can answer it if you can. Sorry about leaving the more brief explanation out.
Accept my answer if it helped! That way someone won't spam this question
Sorry. I thought I accepted it. But it did help me. There is a problem though. It is still doing the same where it only shows the first decal of the gif. I did what you did, but it is still the same.