Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Tool Script Doesnt Toggle SpotLight?

Asked by 1 year ago

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

Log in to vote
0
Answered by 1 year ago

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)
0
this worked! thank yoy JmoneyPlayzOfficial 49 — 1y
Ad

Answer this question