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

How would I make something that I click revert when I click it again?

Asked by 4 years ago

I have a part which as a fire effect, so far I have it that when you click it the fire will be enabled. I don't how to make it when I click it again the fire will be disabled.

Current Script -

1local fire = script.Parent.Fire
2 
3script.Parent.ClickDetector.MouseClick:Connect(function(plr)
4        fire.Enabled = true
5    end)

Currently it's very simple but I have no clue how to go about adding to it.

2 answers

Log in to vote
0
Answered by 4 years ago

try this

01local fire = script.Parent.Fire
02 
03script.Parent.ClickDetector.MouseClick:Connect(function(plr)
04if fire.Enabled == false then
05fire.Enabled = true
06else
07if fire.Enabled = true then
08fire.Enabled = false
09 
10end
11end
12 
13end)
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

You could do like a debounce. So, what it'll do is it'll detect if the condition is true, if it is then Enable the fire, but enabling it will make the condition go 'false', so if you click it again it will not pass the condition, but another if statement that checks whether the condition is false will disable the fire. In this case the fire can be the debounce. A bit confused? Let me give you an example.

01local fire = script.Parent.Fire
02 
03    script.Parent.ClickDetector.MouseClick:Connect(function(plr)
04        if fire.Enabled == false then
05            fire.Enabled = true
06 
07        elseif fire.Enabled == true
08        fire.Enabled = false
09 
10        end
11        end)

Answer this question