Break when touch

guys, how can I break a while loop using Touch:Connect, I had try this but it got red out

while true do
		
	map:WaitForChild("wayout").Wayout.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChildWhichIsA("Humanoid") and hit.Parent:FindFirstChild("Target") then
               break-- I got red out on this 	
		end
	end)
end
1 Like

I’m not sure why you need a while loop if it’s only just the Touched function but it will be something like this:

local breakLoop = true -- if this becomes false loop stops
map:WaitForChild("wayout").Wayout.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChildWhichIsA("Humanoid") and hit.Parent:FindFirstChild("Target") then
       breakLoop = false -- break the running loop
	end
end)
while breakLoop do -- run until breakLoop becomes false
task.wait() -- without this while loop will run too fast
end

thx man, it work!
I need to break the while function when touch because it’s for the escape of my horror game

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.