Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Tool Script Doesnt Toggle SpotLight?

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)

1 answer

✓ Accepted answer

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)

1 comment

0

this worked! thank yoy

This discussion is preserved as it was. New answers, comments, and votes are closed.