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

How would i make a light turn off if i have it on?

So when i turn on the light it lights up but when i want to turn it off i want to click it again How would i do this? Here is the code

local sp = script.Parent
sp.ClickDetector.MouseClick:connect(function()
	local l = Instance.new("PointLight", script.Parent.Parent.light)
	l.Brightness = 11
	l.Range = 11
	l.Shadows = true
end)

--I just want it to shutoff after i click it agian

1 comment

0

Try adding a Debounce-type thing [Forgot what it's called] into your Function 'local Debounce = true if Debounce then Debounce = false elseif not Debounce then Debounce = true end'.

2 answers

I suggest not making one in a script, but putting it there already at script.Parent.Parent.light!

sp.ClickDetector.MouseClick:connect(function()
    	if script.Parent.Parent.light.PointLight.Enabled == false then
		script.Parent.Parent.light.PointLight.Enabled = true
	else if script.Parent.Parent.light.PointLight.Enabled == true then
		script.Parent.Parent.light.PointLight.Enabled = false
end)

So what I mean is put one in the part called light.

If helped then accept answer please!

I'm pretty sure CheeseDevie's will work, but this is a more efficient way of doing it (assuming it'll work with a property instead of value) --

sp.ClickDetector.MouseClick:connect(function()
	script.Parent.Parent.Light.PointLight.Enabled = not script.Parent.Parent.Light.PointLight.Enabled
end)

-- All it does it sets the point light's enabled value to the opposite of what it currently is.

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