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

How can I debounce this? Not really good with them?

Asked by
Azuc 112
6 years ago
local state = false

script.Parent.ClickDetector.mouseClick:connect(function(touched)    

    state = not state
    if state then
        script.Parent.Sound:Play()
        wait(1)
        script.Parent.Off.Windows:Play()
        game.Workspace.KEYBASE.Material = ("Neon")
        wait(3)
    else
        script.Parent.Sound:Play()
        wait(1)
        script.Parent.Off.WindowsOf:Play()
        wait(1)
        game.Workspace.KEYBASE.Material = ("SmoothPlastic")
        wait(4)
    end
end)

2 answers

Log in to vote
1
Answered by 6 years ago

-- Assuming state is the value you want to debounce local state = false script.Parent.ClickDetector.mouseClick:connect(function(touched) state = not state if state then state = true script.Parent.Sound:Play() wait(1) script.Parent.Off.Windows:Play() game.Workspace.KEYBASE.Material = ("Neon") wait(3) state = false else state = false script.Parent.Sound:Play() wait(1) script.Parent.Off.WindowsOf:Play() wait(1) game.Workspace.KEYBASE.Material = ("SmoothPlastic") wait(4) state = true end end)

I'm not too sure what you're trying to do entirely but here's a start. Edit it and see what you can come up with. If not reply with your error.

Ad
Log in to vote
0
Answered by 6 years ago
local state = false

script.Parent.ClickDetector.mouseClick:connect(function(touched)    

    if state == false then
    state= true
        script.Parent.Sound:Play()
        wait(1)
        script.Parent.Off.Windows:Play()
        game.Workspace.KEYBASE.Material = ("Neon")
        wait(3)
    else
        script.Parent.Sound:Play()
        wait(1)
        script.Parent.Off.WindowsOf:Play()
        wait(1)
        game.Workspace.KEYBASE.Material = ("SmoothPlastic")
        wait(4)
    state = false
    end
end)

This should work. Let me know if it doesn't.

Answer this question