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?
01 | local shortcut = game.Workspace.Map |
02 | local lighting = shortcut.Lighting |
03 | local flicker = lighting.Ceiling_light.Lightbulb.SpotLight |
04 | local audio = lighting.Ceiling_light.Lightbulb [ "Lightbulb Flicker" ] |
05 | local audioo = lighting.Ceiling_light.Lightbulb.zap |
06 | local debounce = false |
07 |
08 | script.Parent.Touched:Connect( function () |
09 | if debounce = = false then |
10 | debounce = true |
11 | if script.Parent.Touched then |
12 | audio:play() |
13 | flicker.Brightness = 0 |
14 | wait( 1 ) |
15 | flicker.Brightness = 15 |
wait()
must be put before the debounce changes value. So your code will be this:
01 | local shortcut = game.Workspace.Map |
02 | local lighting = shortcut.Lighting |
03 | local flicker = lighting.Ceiling_light.Lightbulb.SpotLight |
04 | local audio = lighting.Ceiling_light.Lightbulb [ "Lightbulb Flicker" ] |
05 | local audioo = lighting.Ceiling_light.Lightbulb.zap |
06 | local debounce = false |
07 |
08 | script.Parent.Touched:Connect( function () |
09 | if debounce = = false then |
10 | debounce = true |
11 | audio:Play() |
12 | flicker.Brightness = 0 |
13 | wait( 1 ) |
14 | flicker.Brightness = 15 |
15 | audioo:Play() |
Hope it helped, I fixed your code and I put the wait in line 20. If you may encounter problems, comment.