Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

-- 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.

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.