You can make a light var to check if it is on or off by using if statements!
We check if the light var is false to turn it on and make it true. The else keyword will have a code inside when the var is true to be false and turn off the light.
local light = false
script.Parent.ClickDetector.MouseClick:Connect(function()
if light == false then
script.Parent.Transparency = 0
script.Parent.Material = "Neon"
script.Parent.BrickColor = BrickColor.new("New Yeller")
script.Parent.PointLight.Enabled = true
light = true
else
script.Parent.Transparency = 0.5
script.Parent.Material = "Plastic"
script.Parent.BrickColor = BrickColor.new("Dark stone grey")
script.Parent.PointLight.Enabled = false
light = false
end
end)
Explanation:
The variable 'light' is currently set to false.
Once the event fires, it checks if the light variable is true or false.
If true then, it will do:
script.Parent.Transparency = 0
script.Parent.Material = "Neon"
script.Parent.BrickColor = BrickColor.new("New Yeller")
script.Parent.PointLight.Enabled = true
light = true
If false:
script.Parent.Transparency = 0.5
script.Parent.Material = "Plastic"
script.Parent.BrickColor = BrickColor.new("Dark stone grey")
script.Parent.PointLight.Enabled = false
light = false
6 comments
You don't really need a var, you can just check if the light is enabled.
Thank you!
@VitroxVox Yeah, just realised.
On second thought, could you explain the script to me?
@SmockyBocky Edited the answer. Check the answer again.
Thank you, I now understand :D