How would I fix this so it doesn't spam the audio and brightness, but keeps the wait timers in the code without removing debounce?
local shortcut = game.Workspace.Map local lighting = shortcut.Lighting local flicker = lighting.Ceiling_light.Lightbulb.SpotLight local audio = lighting.Ceiling_light.Lightbulb["Lightbulb Flicker"] local audioo = lighting.Ceiling_light.Lightbulb.zap local debounce = false script.Parent.Touched:Connect(function() if debounce == false then debounce = true if script.Parent.Touched then audio:play() flicker.Brightness = 0 wait(1) flicker.Brightness = 15 audioo:play() wait(1) flicker.Brightness = 0 wait(1) flicker.Brightness = 15 end debounce = false end if script.Parent.TouchEnded then end script.Parent:Destroy() end)
wait()
must be put before the debounce changes value. So your code will be this:
local shortcut = game.Workspace.Map local lighting = shortcut.Lighting local flicker = lighting.Ceiling_light.Lightbulb.SpotLight local audio = lighting.Ceiling_light.Lightbulb["Lightbulb Flicker"] local audioo = lighting.Ceiling_light.Lightbulb.zap local debounce = false script.Parent.Touched:Connect(function() if debounce == false then debounce = true audio:Play() flicker.Brightness = 0 wait(1) flicker.Brightness = 15 audioo:Play() wait(1) flicker.Brightness = 0 wait(1) flicker.Brightness = 15 wait(5) -- Replace 5 to how many seconds you want debounce = false end end) script.Parent.TouchEnded:Connect(function() script.Parent:Destroy() end)
Hope it helped, I fixed your code and I put the wait in line 20. If you may encounter problems, comment.