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

If you use "while true do" to loop a script, where do I put that in my script so that I can loop it?

Asked by 6 years ago

How do you loop this script down below??

local TimesClicked = 0
script.Parent.mouseClick:connect(function(Player)
if script.Parent.Parent.CanCollide == true then
Player.leaderstats.LifeFormFound.Value = Player.leaderstats.LifeFormFound.Value +1
TimesClicked = TimesClicked +1
if TimesClicked == 1 then 
script.Parent.Parent.Transparency = 1
script.Parent.Parent.CanCollide = false
wait(3)
script.Parent.Parent.Transparency = 0
script.Parent.Parent.CanCollide = true

end
end
end)

0
it depends on what you want to be looped. what are you trying to do inside the loop? MrMedian 160 — 6y
0
You want to put the loop into the mouseClick event? maumaumaumaumaumau 98 — 6y
0
@maumaumaumaumaumau yes I want it in the mouse click event RainbowBeastYT 85 — 6y
0
Did it work maumaumaumaumaumau 98 — 6y
0
nope, not really it ummm, keep give the currency nonstop, but did not do the transparency and the cancollide command RainbowBeastYT 85 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
local TimesClicked = 0
script.Parent.mouseClick:connect(function(Player)
if script.Parent.Parent.CanCollide == true then
local loop = coroutine.wrap(function()
while wait() do
Player.leaderstats.LifeFormFound.Value = Player.leaderstats.LifeFormFound.Value +1
TimesClicked = TimesClicked +1
end
end)
loop()
end
if TimesClicked == 1 then 
script.Parent.Parent.Transparency = 1
script.Parent.Parent.CanCollide = false
wait(3)
script.Parent.Parent.Transparency = 0
script.Parent.Parent.CanCollide = true

end
end)
0
wait() shouldn't be a condition. User#19524 175 — 6y
1
Yes it can. fredfishy 833 — 6y
1
it is maumaumaumaumaumau 98 — 6y
0
But true would cause in massive lag maumaumaumaumaumau 98 — 6y
View all comments (9 more)
0
Wrong. User#19524 175 — 6y
1
"It doesn't work" "Yes it does" "It's dumb". Lua conditionals aren't based on booleans - they're based on whether or not something is "truthy" or "falsey" like most loosely-typed languages. Since `wait` cannot return 0, it's always "truthy". Arguably it's much neater to do it this way, since it avoids the ubiquitous `wait` which is normally jammed at the end of every loop. fredfishy 833 — 6y
1
0 is also truthy in Lua amanda 1059 — 6y
0
true > wait(). User#19524 175 — 6y
0
@amanda ooh that's a fun one @incapaz wait() > true, since you've provided literally no counterargument other than "it's dumb" fredfishy 833 — 6y
0
print(wait() > true) --> false print(true > wait()) --> true User#19524 175 — 6y
0
Unfortunately, your code doesn't interpret since you can't compare a boolean to a numeric value with `>`. fredfishy 833 — 6y
0
i was joking lol. i don't care tbh User#19524 175 — 6y
0
Do. ADIMAngelSeirra 5 — 6y
Ad

Answer this question