script.Parent.ClickDetector.MouseClick:Connect(function() script.Parent.Transparency = 0 script.Parent.Material = "Neon" script.Parent.BrickColor = BrickColor.new("New Yeller") script.Parent.PointLight.Enabled = true wait(300) script.Parent.Transparency = 0.5 script.Parent.Material = "Plastic" script.Parent.BrickColor = BrickColor.new("Dark stone grey") script.Parent.PointLight.Enabled = false end)
How can I make it so that I can click the light a second time to turn it off, without waiting 500 seconds? I'm new to scripting, just so you know.
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 -- Makes the transparency 0 script.Parent.Material = "Neon" -- Change Material to 'Neon' script.Parent.BrickColor = BrickColor.new("New Yeller") -- 'Brick color 'New Yeller'' script.Parent.PointLight.Enabled = true -- PointLight property = true light = true -- The var will turn to true in order to turn it off when clicked again since the if statement checks if it is false or true
If false:
script.Parent.Transparency = 0.5 -- Makes the transparency 0.5 script.Parent.Material = "Plastic"-- Change Material to 'Plastic' script.Parent.BrickColor = BrickColor.new("Dark stone grey")-- Brick color 'Dark stone grey' script.Parent.PointLight.Enabled = false -- PointLight property = false light = false -- The var will turn to false in order to turn it on when clicked again since the if statement checks if it is false or true