Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can i toggle a boolean value?

I want to toggle a boolean value if someone clicks a button. I got it to work that if they click it will go on and stay on for 2 minutes. But i would like to toggle the value if they click, not just turn it true for 2 minutes. Can someone help me please?

local toggle = game.Workspace.EmergencyLight.Toggle

script.Parent.mouseClick:connect(function()
	toggle.Value = true
	wait(120)
	toggle.Workspace.EmergencyLight.Toggle.Value = false
end)

2 comments

0

You took your variable & combined it w/ it's information on line 6 lol; just simply change it to "toggle.Value" (line 6) and it'll work again. :)

0

The script above works. It's that i want it to be toggled instead of the wait

1 answer

You can use

 toggle.Value = not toggle.Value

This line assigns the value of toggle to the opposite of its current value. Since a boolean only has two possible values, it is toggled.

1 comment

0

Where to place that?

This discussion is preserved as it was. New answers, comments, and votes are closed.