im making a script that checks wether the torch is on or off, and changes it, but its not working, can anyone help
local isEnabled = false local light = script.Parent.Light script.Parent.Activated:Connect(function() if script.Parent.IsEnabled == false then light.Color = Color3.new(0.972549, 0.85098, 0.427451) light.Material = Enum.Material.Neon light.SpotLight.Enabled = true isEnabled = true end end) script.Parent.Activated:Connect(function() if script.Parent.IsEnabled == true then light.Color = Color3.new(0, 0, 0) light.Material = Enum.Material.SmoothPlastic light.SpotLight.Enabled = false isEnabled = false end end)
You don't need to connect it twice, you can just use else
.
Also, tools don't have the IsEnabled property. Use the variable isEnabled
instead. (Alternatively, you can use light.SpotLight.Enabled
instead)
local tool = script.Parent local light = script.Parent.Light tool.Activated:Connect(function() light.SpotLight.Enabled = not light.SpotLight.Enabled -- opposite if light.SpotLight.Enabled then -- true light.Color = Color3.new(0.972549, 0.85098, 0.427451) light.Material = Enum.Material.Neon else -- false light.Color = Color3.new(0, 0, 0) light.Material = Enum.Material.SmoothPlastic end end)