fl_xed
(persian)
March 7, 2021, 3:35am
#1
So im trying to constantly change the background image for an aesthetic for my Admin UI
But whenever it switches it’s just white instead of the image, any help please
FOR = script.Parent
wait(3)
FOR.Image = “rbxassetid://6485314800”
wait(0.9)
FOR.Image = “rbxassetid://6485315210”
wait(0.9)
FOR.Image = “rbxassetid://6485315511”
wait(0.9)
FOR.Image = “rbxassetid://6485316673”
wait(0.9)
FOR.Image = “rbxassetid://6485317344”
With Loop:
local FOR = script.Parent
local FORE = false
while wait() do
if FORE == false then
FORE = true
wait(3)
FOR.Image = "rbxassetid://6485314793"
wait(0.9)
FOR.Image = "rbxassetid://6485315203"
wait(0.9)
FOR.Image = "rbxassetid://6485315505"
wait(0.9)
FOR.Image = "rbxassetid://6485316669"
wait(0.9)
FOR.Image = "rbxassetid://6485317340"
wait(0.9)
FORE = false
end
end
Without Loop:
local FOR = script.Parent
wait(3)
FOR.Image = "rbxassetid://6485314793"
wait(0.9)
FOR.Image = "rbxassetid://6485315203"
wait(0.9)
FOR.Image = "rbxassetid://6485315505"
wait(0.9)
FOR.Image = "rbxassetid://6485316669"
wait(0.9)
FOR.Image = "rbxassetid://6485317340"
2 Likes
fl_xed
(persian)
March 7, 2021, 4:14am
#3
Thank you so much for this, who knew all I had to add was a local.
Sorry, you got confused. You didn’t need to add local. I just added it because it’s better to use. I converted the id’s (which were decal id’s) to image id’s.
fl_xed
(persian)
March 7, 2021, 5:42am
#6
why is it better practice tho?
Local variables are quicker to access, as a simple answer. If needed, more information about this can be found from the following posts:
A local function defined as such…
local function ABC() end
…is literally just syntactic sugar for:
local ABC
ABC = function() end
I would prefer using local function ABC() ... end in most cases unless you’re forced to assign a function to the variable at a different time.
In terms of when to use them: always. Always prefer local variables over global. They’re faster for Lua to access due to the different memory locations used for each (albeit it’s a small difference, but good practice none…
Is there any advantage to declaring a function as local ?
Yes. They are faster to access, and you avoid polluting the global* namespace. Here is some info about the global environment from PIL.
For simple programs, honestly, it probably doesn’t matter what you do. As your programs get more complex, though, you will start to realize the benefits of well-defined scope.
Because so far I’ve only seen disadvantages : without local , the function can be located anywhere in the code and when decl…
1 Like