Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

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

Asked by 5 months 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 -

local fire = script.Parent.Fire

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
        fire.Enabled = true 
    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 5 months ago

try this

local fire = script.Parent.Fire

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
if fire.Enabled == false then
fire.Enabled = true
else
if fire.Enabled = true then
fire.Enabled = false

end
end

end)
Ad
Log in to vote
0
Answered by 5 months ago
Edited 5 months 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.

local fire = script.Parent.Fire

    script.Parent.ClickDetector.MouseClick:Connect(function(plr)
        if fire.Enabled == false then
            fire.Enabled = true

        elseif fire.Enabled == true
        fire.Enabled = false

        end
        end)

Answer this question