So basically, I'm trying to make it so when a button is pressed, the smoke turns on, That part works, however, I'm trying to make it so you can disable it with a debounce. If you can, please help.
01 | local enabled = false |
02 | local debounce = false |
03 | local Model = script.Parent.Parent.Parent.gas |
04 | script.Parent.ClickDetector.MouseClick:Connect( function () |
05 | for i,v in pairs (Model:GetChildren()) do |
06 | if not debounce then |
07 | if enabled = = false then |
08 | v.Smoke.Enabled = true |
09 | wait( 3 ) |
10 | debounce = false |
11 | if v.Smoke.Enabled = = true then |
12 | v.Smoke.Enabled = false |
13 | end |
14 | end |
15 | end |
16 | end |
17 | end ) |
You need to set the debounce to true because after the check is completed you only want it to work only once, right? If you want it to only work once then set the debounce to true after the debounce check because other iterations will check the if statement again and the debounce will be true, making it not pass the debounce check.
01 | local enabled = false |
02 | local debounce = false |
03 | local Model = script.Parent.Parent.Parent.gas |
04 | script.Parent.ClickDetector.MouseClick:Connect( function () |
05 | for i,v in pairs (Model:GetChildren()) do |
06 | if not debounce then |
07 | debounce = true |
08 | if enabled = = false then |
09 | v.Smoke.Enabled = true |
10 | wait( 3 ) |
11 | debounce = false |
12 | if v.Smoke.Enabled = = true then |
13 | v.Smoke.Enabled = false |
14 | end |
15 | end |
16 | end |
17 | end |
18 | end ) |
01 | local enabled = false |
02 | local debounce = false |
03 | local Model = script.Parent.Parent.Parent.gas |
04 | script.Parent.ClickDetector.MouseClick:Connect( function () |
05 | for i,v in pairs (Model:GetChildren()) do |
06 | if debounce = = false then |
07 | if enabled = = false then |
08 | debounce = true |
09 | v.Smoke.Enabled = true |
10 | wait( 3 ) |
11 | debounce = false |
12 | if v.Smoke.Enabled = = true then |
13 | v.Smoke.Enabled = false |
14 | end |
15 | end |
16 | end |
17 | end |
18 | end ) |