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

Is there a way to break a script using events?

Asked by 6 years ago

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!

1
Paste your code in hellmatic 1523 — 6y
0
if u wanna break the script then disable it see easy awesomeipod 607 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
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
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! DaWarTekWizard 169 — 6y
Ad

Answer this question