local part = workspace.Part local spotlight = part.SpotLight local Enabled = true script.Parent.ClickDetector.MouseClick:connect(function() if spotlight == Enabled then Enabled = false elseif Enabled == true then Enabled = true end end)
if you can, explain the answer so i can learn :3
Ok, so basically spotlights have a property called .Enabled, this tells the spotlight whether the light will be on or off. It's also boolean value, which means it's property can be set to true or false. If the .Enabled property is set to true, then the light will shine, if it's set to false, then the light won't shine.
local part = workspace.Part local spotlight = part.SpotLight local Enabled = true script.Parent.ClickDetector.MouseClick:connect(function() Enabled = not Enabled -- This will make Enabled false if Enabled is true, this will also make Enabled true if Enabled is false spotlight.Enabled = Enabled end)