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

How do I put a wait() in a if statement that has debounce in it?

Asked by 4 years ago
Edited 4 years ago

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?

01local shortcut = game.Workspace.Map
02local lighting = shortcut.Lighting
03local flicker = lighting.Ceiling_light.Lightbulb.SpotLight
04local audio = lighting.Ceiling_light.Lightbulb["Lightbulb Flicker"]
05local audioo = lighting.Ceiling_light.Lightbulb.zap
06local debounce = false
07 
08script.Parent.Touched:Connect(function()
09if 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
View all 27 lines...

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

wait() must be put before the debounce changes value. So your code will be this:

01local shortcut = game.Workspace.Map
02local lighting = shortcut.Lighting
03local flicker = lighting.Ceiling_light.Lightbulb.SpotLight
04local audio = lighting.Ceiling_light.Lightbulb["Lightbulb Flicker"]
05local audioo = lighting.Ceiling_light.Lightbulb.zap
06local debounce = false
07 
08script.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()
View all 27 lines...

Hope it helped, I fixed your code and I put the wait in line 20. If you may encounter problems, comment.

0
It fixed my problem, thank you. Zeta_Dev 34 — 4y
0
No problem, glad I've helped. Gabe_elvin1226aclan 323 — 4y
Ad

Answer this question