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

How to make a light switch go on and off?

1 answer

✓ Accepted answer

So this is written from a tablet sooooo stick with me here.


-- put this script in the part you want to be clicked on to enable the light

local Light = script.Parent.Parent.SurfaceLight -- the light 
local Activation_Distance = 10 -- how many studs away it can be activated



local clicker = Instance.new("ClickDetector")
clicker.Parent = script.Parent
clicker.MaxActivationDistance = Activation_Distance

local db = false

clicker.MouseClick:Connect(function()
	if not db then -- if the variable (db) is false
		light.Enabled = true -- enable the light
	else -- if the variable (db) is true
		light.Enabled = false -- disable the light
	end
	db = not db -- make the variable (db) the opposite of itself
end)

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