Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Is there a way to make this .gif work on GUI?

Asked by 9 years ago

Please provide more explanation in your question. If you explain exactly what you are trying to accomplish, it will be much easier to answer your question correctly.

I want to make a intro for my game using gif. I got the IDs for the decals to make it into a gif. This script is the one that was answered before for an easier way to put all IDs in one thing. The only thing that was changed was word Texture to Image since it was inserted in ImageLabel. Now when I hit Play to see if the .gif is working, all it did was just show the first picture. This is how it is inserted on StarterGui and the script for it:

Set up in StarterGui in Studio:

--StarterGui
  --ScreenGui
   --Frame
    --ImageLabel
     --Script

Script in GIF for ScreenGui:

local Frames = {251495903,251495914,251495930,251495944,251495974}
while wait() do
    for i,v in pairs (Frames) do
        script.Parent.Image = "http://www.roblox.com/asset/?id="..v
        wait(0.05)
    end
end
0
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. FearMeIAmLag 1161 — 9y
0
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. RobotChitti 167 — 9y
0
Accept my answer if it helped! That way someone won't spam this question EzraNehemiah_TF2 3552 — 9y
0
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. RobotChitti 167 — 9y

1 answer

Log in to vote
3
Answered by 9 years ago

I will only give you some tips.


  1. 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.
  2. Do not use while loops, use RunService instead.
  3. 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()) --Prints something like: 0.031636467
print(wait(0.05)) --Prints something like: 0.0512318631

Fun Facts about Wait

  1. 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
--Both run at the exact same speed.
game:GetService("RunService").Heartbeat:connect(function()
    print("SPAM")
end)

Fun Facts about While Loops and RunService

  1. While loops cause lag! RunService does not.
  2. 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

  1. 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} --A Table/Array doesn't NEED to be local.
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

  1. Use the preloader so all the gif get loaded so they aren't black.
--Add this after line 4.
game:GetService("ContentProvider"):Preload("http://www.roblox.com/asset/?id="..Frames[frame])
0
Thanks Mr. LordDragonZord. This helped me a lot. I mean A LOT. A lot of things that I never knew were supposed to be there or at least what it supposed to. Thank you so much! RobotChitti 167 — 9y
0
1/60th of a second is as fast as the eye can see. For flawless playback use renderstepped. Your eye can still detect flaws in wait() YellowoTide 1992 — 9y
0
@YellowTide, most animations are made in 24, 25, or 30 fps. So if a movie runs at 1/60th of a second, the animation/gif will run 2x faster, which would be better, but in most cases, not. EzraNehemiah_TF2 3552 — 9y
Ad

Answer this question