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

how do i make this toggle work?

Asked by 9 years ago
01local part = workspace.Part
02local spotlight = part.SpotLight
03local Enabled = true
04 
05script.Parent.ClickDetector.MouseClick:connect(function()
06    if spotlight == Enabled then
07        Enabled = false
08    elseif Enabled == true then
09        Enabled = true
10 
11    end
12end)

if you can, explain the answer so i can learn :3

1 answer

Log in to vote
2
Answered by
4Bros 550 Moderation Voter
9 years ago

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.

1local part = workspace.Part
2local spotlight = part.SpotLight
3local Enabled = true
4 
5script.Parent.ClickDetector.MouseClick:connect(function()
6    Enabled = not Enabled -- This will make Enabled false if Enabled is true, this will also make Enabled true if Enabled is false
7    spotlight.Enabled = Enabled
8end)
Ad

Answer this question