#why does my script go on an infinite loop even though i have task.wai(1)?

1 messages · Page 1 of 1 (latest)

vast linden
#

my script:

"local part = script.Parent

part.Touched:connect(function(hit)
local character = hit.parent
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
while true do
task.wait(1)
print("hello")
end
end
end)"

Before the while loop runs it should wait one second everytime no?

lunar trench
#

bro a while true do loop runs forever

#

task.wait adds 1 second to each interval before a new one happens

#

so even if you do a .Touched connection it makes a new connection

#

and the while loop jus goes on and on

outer depot
#

bro you literally have "while true do"

velvet gale
frank forgeBOT
#

studio** You are now Level 3! **studio

vast linden
lunar trench
#

dude everytime you touch it

#

it makes a new connection

#

which causes multiple loops to happen

half junco
#

timmy understand that the task.wait(1) does run. Rascal berry said that multiple loops will happen which is correct since many Touched events will fire. so if you only want 1 touch then you have to check for the player and exit if he already touched once or not