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

My gif playback script is not working like it's supposed to, help! (?)

FPS = 1 -- How many frames per second it will run at.



GIF = {"rbxassetid://614166207","http://www.roblox.com/asset/?id=614196198,rbxassetid://614212267","rbxassetid://614243948","rbxassetid://614245502","rbxassetid://614624256","rbxassetid://614652355","rbxassetid://614749146","rbxassetid://614750178","http://www.roblox.com/asset/?id=166249907","rbxassetid://614751359","rbxassetid://614755688","rbxassetid://614756818","http://www.roblox.com/asset/?id=166249942","http://www.roblox.com/asset/?id=166249964","rbxassetid://614758943","rbxassetid://614761035","rbxassetid://614764045","http://www.roblox.com/asset/?id=166250031"} 
script.Parent:WaitForChild("ImageLabel")
ImageLabel = script.Parent.ImageLabel


for N,F in ipairs(GIF) do
    game:GetService("ContentProvider"):Preload(F) -- This is supposed to preload each image, so images don't blindingly flash people in the face.
 --But instead, this line of code just decides just not to work and blind me with every flash,help?
end


while true do
    for N,F in ipairs(GIF) do -- Run through the GIF table.
        ImageLabel.Image = F
        wait(0.1/FPS)

-- ... My previous code
print("Assets are loading...")

while ContentProvider.RequestQueueSize > 0 do
    wait() -- Of course we'll add some delay so this loop doesn't try to comprehend infinity.
end

print("Assets loaded!")

    end
end

-- I edited the code, but the script is treating it like everything that was added tot he script doesn't exist, help?!

2 comments

0

Help?

0

You have a link instead of rbxassetid:// in there (the 2nd one) suggest changing that.

2 answers

Preloading


The Preload method of ContentProvider doesn't wait for an asset to finish loading. Instead, it requests the asset to be loaded, and will carry on running the rest of your code while it does so.

Solution


A simple solution, is using the RequestQueueSize of ContentProvider, which is an integer that represents how many more asset requests are in queue to finish loading. If the RequestQueueSize is greater than 0, there are still asset requests pending. We could simply use this as a condition for a loop, to keep it running until there are no more requests in queue:

-- ... your previous code
print("Assets are loading...")

while ContentProvider.RequestQueueSize > 0 do
	wait() -- Of course we'll add some delay so this loop doesn't try to comprehend infinity.
end

print("Assets loaded!")

This would wait for all assets to finish loading before resuming the rest of your script.

Side notes


  • Local

    • You should also get in the habit of using local variables, for they're accessed quicker due to their location in memory being local to the scope it was created in. They also have other uses besides just optimizing, which you can read about here.
  • Reference

    • Instead of calling GetService on game each iteration, you should save the reference to the service you're requesting if you're going to be using it more than once (just as you should create a variable for anything you'll use more than once). Example:
     local ContentProvider = game:GetService("ContentProvider")
    

Hope this helped, just let me know if you have any questions.

6 comments

0

Hi, my script still isn't working currently, I edited the code above with yours and still no luck? What have I done wrong?

0

while true do loop place AFTER script which he posted

0

Why are you waiting for the assets to load after you render them? You should be waiting for them to load before you try and render them.

0

my bad, edited is it correct now?

0

No. You don't want to start rendering any of those images until they're all loaded. You wait for them first, then you can start using them without worrying about waiting on the image.

0

what about having the next 5 images or something already loaded

EDIT: Fixed assets preloading, changed variables to local, made ContentProvider Variable and deleted not important lines with finding ImageLabel Now it might work

local FPS = 10 -- How many frames per second it will run at.
local ContentProvider = game:GetService("ContentProvider")



local GIF = {"rbxassetid://614166207","http://www.roblox.com/asset/?id=614196198,rbxassetid://614212267","rbxassetid://614243948","rbxassetid://614245502","rbxassetid://614624256","rbxassetid://614652355","rbxassetid://614749146","rbxassetid://614750178","http://www.roblox.com/asset/?id=166249907","rbxassetid://614751359","rbxassetid://614755688","rbxassetid://614756818","http://www.roblox.com/asset/?id=166249942","http://www.roblox.com/asset/?id=166249964","rbxassetid://614758943","rbxassetid://614761035","rbxassetid://614764045","http://www.roblox.com/asset/?id=166250031"} 

local ImageLabel = script.Parent:WaitForChild("ImageLabel")


for _, i in pairs(GIF) do
    ContentProvider:Preload(i) -- This is supposed to preload each image, so images don't blindingly flash people in the face.
 --But instead, this line of code just decides just not to work and blind me with every flash,help?
end

-- ... My previous code
print("Assets are loading...")

while ContentProvider.RequestQueueSize > 0 do
    wait() -- Of course we'll add some delay so this loop doesn't try to comprehend infinity.
end

print("Assets loaded!")


while true do
    for i = 1, #GIF, 1 do -- Run through the GIF table.
        ImageLabel.Image = GIF[i]
        wait(1/FPS)
    end
end




8 comments

0

Update: Now its working (added ContentProvider variable)

0

Thank you, but for some reason the flashing is still occurring, i'm currently in studio

0

I am trying to stop the flashing from happening.

0

what do You mean with flashing?

0

@kurkai123 Kind of like strobe lights. Like a blank picture flashes into view between every frame, or in this case, before every loaded image label in the gif. The flash doesn't happen when I use this script with decals, but it happens when I do so with ImageLabels.

0

Idk whybut I prefer using decals then :|

0

How can you use decals in a GUI?

0

You cant use decals in the gui

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