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

how do i make this toggle work?

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

1 answer

✓ Accepted answer

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)

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