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

What am I doing wrong with my for loop?

Asked by 7 years ago
Edited 7 years ago

So this is my script which slowly turns another brick known as "seed" invisible if a player steps on another part.

local seed = game.Workspace.Seed
script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid")then 
        for i= 0,1,-0.01  do
        seed.Transparency = i

wait()
    end
end
end)

It works only If I get rid of the for loop, and change it to 'seed.Transparency = 1'. Why is this? Do for loops not work with functions and 'FindFirstChild'?

1 answer

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

You need to change your (-0.01 to 0.01) and the wait to (0.01)

finished code=

local seed = game.Workspace.Seed
script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid")then 
        for i= 0,1,0.01  do
        seed.Transparency = i

wait(0.01)
    end
end
end)

Explanation: So you were making it go up to 1, but in your 3rd argument you were making it go down basically making it useless

The 3rd argument determines if the number goes up, or down

Did this help? Make sure to accept the answer?

Does it not work? Make sure to comment what is wrong and I'll fix it!

(sorry if this is explained terribly)

0
Oh! Thank you so much, you explained it perfectly and it worked. One more thing, how do I disconnect this function so I can only make it happen once? crystalclay 70 — 7y
0
I don't think there is a proper function to 'disconnect it DeveloperSolo 370 — 7y
0
Never mind, I found out how now. crystalclay 70 — 7y
0
alright, I didn't finish my answer. You could always use a denounce variable tho. if needed DeveloperSolo 370 — 7y
0
Oh, okay thanks crystalclay 70 — 7y
Ad

Answer this question