Hai! I have a touched event that hosts a while loop on touched but when I finish the touch, the while loop stays. I understand there is a Touch Ended event but thinking how to do this ponders my mind. Sorry if I don't make much sense, I am not asking for a free script but merely a method. Thanks!
✓ ANSWER ACCEPTED
Is there a way to break a script using events?
1 answer
✓ Accepted answer
local part = -- Define your part
local enable = false
function onTouched()
enable = true
while true do
if enable == false then return end
-- Your code goes here
end
end
function onTouchEnded()
delay(0.5,function()
enable = false
end)
end
part.Touched:Connect(onTouched)
part.TouchEnded:Connect(onTouchEnded)
1 comment
1
Yeah I figured a debounce would work. I used a bool in my case for simplicity. Thank you anyways! Fixed mine before reading this. I will accept answer anyways because I am not like those little children who don't appreciate my answers!
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
Paste your code in
if u wanna break the script then disable it see easy