As you can see the script waits 2 seconds before it allows you to switch the light back on or off and that works perfectly but the issue is that when you repeatedly click the switch the sounds are still going to play either way and i don’t know how to fix that. I only want the sounds to play once when the switch is clicked on or off. Thank you for your time.
Thank you for replying. I did try that but unfortunately when i spam the button the sound still plays more than once and doesnt wait for the switch to actually change from on to off
If I’m being honest, I do know how to fix your script, what you need to do is wrap the code in a debounce check, then use a logic for detecting if the light is on or off, then deciding how to change the light’s status. But I’m on my phone and the code isn’t pasting right so my bad. Someone will solve it soon
Debounces need to have an option to do nothing, but both logic conditions have some code to run.
Try this format:
local tweens = {
On = tweenserv:Create(switch, TweenInfo.new(0.5, Enum.EasingStyle.Quad), {Orientation = On.Orientation}),
Off = tweenserv:Create(switch, TweenInfo.new(0.5, Enum.EasingStyle.Quad), {Orientation = Off.Orientation})
}
local state = "Off"
cd.MouseClick:Connect(function()
if clicked == false then
clicked = true
if state == "On" then
state = "Off"
else
state = "On"
end
tweens[state]:Play()
wait(0.5)
switch:WaitForChild(state.."Sound"):Play()
wait(2)
clicked = false
end
end)
for some reason im getting an error in the table you wrote. The “Off” statement is showing up red. Also it doesn’t work and i don’t really understand why