Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

5 comments

0

it depends on what you want to be looped. what are you trying to do inside the loop?

0

You want to put the loop into the mouseClick event?

0

@maumaumaumaumaumau yes I want it in the mouse click event

0

Did it work

0

nope, not really it ummm, keep give the currency nonstop, but did not do the transparency and the cancollide command

1 answer

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)

13 comments

0

wait() shouldn't be a condition.

1

Yes it can.

1

it is

0

But true would cause in massive lag

0

Wrong.

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.

1

0 is also truthy in Lua

0

true > wait().

0

@amanda ooh that's a fun one @incapaz wait() > true, since you've provided literally no counterargument other than "it's dumb"

0

print(wait() > true) --> false print(true > wait()) --> true

0

Unfortunately, your code doesn't interpret since you can't compare a boolean to a numeric value with >.

0

i was joking lol. i don't care tbh

0

Do.

This discussion is preserved as it was. New answers, comments, and votes are closed.