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

How to make a light switch go on and off?

Asked by 5 years ago
game = Click light0
game = Click light10
Part:Do
0
This code makes me smile Fad99 286 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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)
Ad

Answer this question