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

Light Switches?

Asked by 10 years ago

How do I make a on/off button for a point light or a spot light?

5 answers

Log in to vote
2
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 years ago

Here you go:

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

So here is how you should order your parts:

1.Create the switch/brick. 2.Put the PointLight/SpotLight in it. 3.Put a ClickDetector in the brick as well.

-Thank me by accepting this answer/bumping up my reputation!

Ad
Log in to vote
0
Answered by 10 years ago

function switch()

w = workspace.whatever if w.Transparency == 0 then w.Transparency == 1 elseif w.Transparency == 1 then w.Transparency == 0 end end

--connection line

0
how do you do that lua format :( Yumeragon 45 — 10y
Log in to vote
0
Answered by 10 years ago

I did it similar to Shawnyg, but I used the range value instead. So you can choose how bright it is via code.

local onoff = 2 

--- onoff = 2 then light is on
--- onoff = 1 then light is off

function onClicked(playerWhoClicked)
    if onoff == 1 then
        script.Parent.SpotLight.Range = 10
        onoff = 2
        else
        script.Parent.SpotLight.Range = 0
        onoff = 1
    end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

If onoff equals 2 at the start, the light is already on prior to the game starting. If onoff equals 1 at the start, the light is off prior to the game starting.

That code also assumes that the Script, ClickDetector and SpotLight is in the same brick.

This code also applies to a PointLight, you just have to change the word SpotLight to PointLight.

Log in to vote
0
Answered by 4 years ago

ok so ibasically im very smol

Log in to vote
-5
Answered by 10 years ago

You can always reuse someones old light switch and create your own with that tool. If you want to start from scratch I suggest making the model before you add scripting.

But it's mainly just scripting. I never had time to go around creating the first ROBLOX light bulb, luckily other people did that for us.

Answer this question