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

My local script that uses "for i" doesn't seem to work?

Asked by 7 years ago

This is a local script that uses the function "for i" to change transparency. It does not work, it does not even show any errors in output or script analysis. Help!

Here is the script:

local gui = script.Parent
local frame = gui.Frame
local warning = frame.Warning
warning.ImageTransparency = 1

while true do
    wait()

for i = 0, 1, 0.1 do
    warning.ImageTransparency = i
end
    wait()
for i = 1, 0, 0.1 do
    warning.ImageTransparency = i
end

end
0
Does the image remain transparent or is it not transparent at all once this script runs Ethan_Waike 156 — 7y
0
It is not transparent until the script runs. flufffybuns 89 — 7y

1 answer

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
7 years ago

Your script is mostly working, but it's doing its job very quickly.

It assigns transparency to 0, then 0.1, then 0.2, then 0.3, then 0.4, then 0.5, ...., then 1.

But it does all of that without pausing, so you will only be able to see the last assignment.

You need a wait() inside your loop in order to see it.


In order to count backwards, you have to say -0.1 instead of 0.1.


Tab your code correctly -- it makes it much easier to figure out which things belong to which loops / conditions.

while true do
    for i = 0, 1, 0.1 do
        warning.ImageTransparency = i
        wait() -- added
    end

    for i = 1, 0, -0.1 do -- 0.1 should be -0.1
        warning.ImageTransparency = i
        wait() -- added
    end
end

0
Thank you! Now I know what to do in the future. flufffybuns 89 — 7y
Ad

Answer this question