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

How would i make a light turn off if i have it on?

Asked by 10 years ago

So when i turn on the light it lights up but when i want to turn it off i want to click it again How would i do this? Here is the code

local sp = script.Parent
sp.ClickDetector.MouseClick:connect(function()
    local l = Instance.new("PointLight", script.Parent.Parent.light)
    l.Brightness = 11
    l.Range = 11
    l.Shadows = true
end)

--I just want it to shutoff after i click it agian
0
Try adding a Debounce-type thing [Forgot what it's called] into your Function 'local Debounce = true if Debounce then Debounce = false elseif not Debounce then Debounce = true end'. TheeDeathCaster 2368 — 10y

2 answers

Log in to vote
1
Answered by 10 years ago

I suggest not making one in a script, but putting it there already at script.Parent.Parent.light!

sp.ClickDetector.MouseClick:connect(function()
        if script.Parent.Parent.light.PointLight.Enabled == false then
        script.Parent.Parent.light.PointLight.Enabled = true
    else if script.Parent.Parent.light.PointLight.Enabled == true then
        script.Parent.Parent.light.PointLight.Enabled = false
end)

So what I mean is put one in the part called light.

If helped then accept answer please!

Ad
Log in to vote
0
Answered by
RoboFrog 400 Moderation Voter
10 years ago

I'm pretty sure CheeseDevie's will work, but this is a more efficient way of doing it (assuming it'll work with a property instead of value) --

sp.ClickDetector.MouseClick:connect(function()
    script.Parent.Parent.Light.PointLight.Enabled = not script.Parent.Parent.Light.PointLight.Enabled
end)

-- All it does it sets the point light's enabled value to the opposite of what it currently is.

Answer this question