I need help to script a light with light switches in if you got any scripts that can help please let me know.
✓ ANSWER ACCEPTED
Light controlled with light switch?
2 answers
✓ Accepted answer
Well, i suggest this:
- Your LightSwitch should have a ClickDetector inside it.
- your Light part should have PointLight, SurfaceLight or SpotLight inside it.
local LightSwitch = workspace.LightSwitch --Imagine your light switch is in Workspace.
local Light = workspace.Light.PointLight --Imagine you have a part where there's a PointLight, disable the "Enabled" property of PointLight.
local LightOn = false --This tells the script if the light is on or off, if you want your light to be on already, change the "false" to "true"
LightSwitch.ClickDetector.MouseClick:connect(function() --When you click the Light Switch...
if LightOn == false then --If the light is off when you click the Light Switch...
Light.Enabled = true --The light will turn on.
LightOn == true --This tells the script the light is already on.
elseif LightOn ~= false then --If the light is on when you click the Light Switch...
Light.Enabled = false --The light will turn off.
LightOn == false --This tells the script the light is already off.
end
end)
Hope this helped!
Make a model with 2 parts. Insert a PointLight into the part that will have the light, and a ClickDetector into the switch. Now insert this script into the Model
local Light = script.Parent.(name of the light soruce)
local Switch = script.Parent.(name of the switch)
local On = false
Switch.ClickDetector.MouseClick:Connect(function()
if not On then
Light.PointLight.Enabled = true
On = true
else
Light.PointLight.Enabled = false
On = false
end
end)
Make sure that the light is disabled by default. If not change "On" to false
This discussion is preserved as it was. New answers, comments, and votes are closed.
