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

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.

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)

Ad

Answer this question