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

Loop isn't working?

Asked by 8 years ago

I tried making a script in which the brick slowly disappears and then slowly reappears after, and this goes on infinitely. But it isn't working, here is the script:

t = script.Parent.Transparency

while true do
    for i=1,10 do
        t = t + 0.1
        wait(1)
    end
    wait(1)
    for i=1,10 do
        t = t + 0.1
        wait(1)
    end
end

2 answers

Log in to vote
0
Answered by
iNicklas 215 Moderation Voter
8 years ago
local t = script.Parent

while true do

    for i=1,10 do
        t.Transparency = t.Transparency + 0.1 -- Addend
        wait(1)
    end

    for i=1,10 do
        t.Transparency = t.Transparency - 0.1 -- Subtraction
        wait(1)
    end
end
0
Alright thanks it worked, so do you have to change properties inside of the loop instead of defining them in the variable? Cause I can see that you changed it to where it changes the transparency inside the loop. Either way I'll accept the answer. ghostblocks 74 — 8y
0
oh finnaly you understood!! davness 376 — 8y
Ad
Log in to vote
0
Answered by
davness 376 Moderation Voter
8 years ago

The script is going disappear forever cause you are ALWAYS adding transparency:

t = script.Parent.Transparency

while true do
    for i=1,10 do
        t = t + 0.1
        wait(1)
    end
    wait(1)
    for i=1,10 do
        t = t - 0.1 -- you said here t = t + 0.1
        wait(1)
    end
end

Protip: Instead of adding, you can make the things happen on i var, like this:

t = script.Parent.Transparency

while true do
    for i = 0, 1, 0.1 do -- it goes from 0 to 1, adding 0.1
        t = i
        wait(1)
    end
    wait(1)
    for i = 1, 0, -0.1 do -- going from 1 to 0, subtracting 0.1
        t = i
        wait(1)
    end
end

as everyone on the comments and I said, you should give objects to the vars and changing their properties, like this:

t = script.Parent

while true do
    for i = 0, 1, 0.1 do -- it goes from 0 to 1, adding 0.1
        t.Transparency = i
        wait(1)
    end
    wait(1)
    for i = 1, 0, -0.1 do -- going from 1 to 0, subtracting 0.1
        t.Transparency = i
        wait(1)
    end
end
0
Thanks for making it more efficient, but for some reason it still isn't working. ghostblocks 74 — 8y
1
try using t = script.Parent and t.Transparency = i davness 376 — 8y
0
You're script is maybe disabled XToonLinkX123 580 — 8y
0
anything in the output? davness 376 — 8y
View all comments (4 more)
0
You can't use properties in variables as the variables only store the value of the property. What dav said above will work if you use t = script.Parent and t.Transparency = i. Spongocardo 1991 — 8y
0
@Spongecardo, you can set properties as a variable and use them, it only errors when you try to edit the variable EzraNehemiah_TF2 3552 — 8y
0
now he can understand :) davness 376 — 8y
0
@Lord Yeah, that's what I was trying to say. Spongocardo 1991 — 8y

Answer this question