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

Why doesn't this flashlight work upon equipping a second time?

Asked by
Foridex 46
5 years ago
local light = script.Parent.Light
local pointlight = light.PointLight
local tool = script.Parent
local click = script.Parent.Handle.Click
local equip = script.Parent.Handle.Equip

tool.Equipped:connect(function()
    equip:Play()
    tool.Activated:connect(function()
        light.Material = "Neon"
        light.BrickColor = BrickColor.new("New Yeller")
        pointlight.Enabled = not pointlight.Enabled
        click:Play()
    end)
    tool.Unequipped:connect(function()
        light.Material = "Glass"
        light.BrickColor = BrickColor.new("Medium stone grey")
        pointlight.Enabled = false
        click:Play()
    end)
end)

This script works when its first equipped, but i reequip it it stops working until i equip it again.

Also how can I make the neon work?

1 answer

Log in to vote
0
Answered by 5 years ago

This is because of line 15. You wrapped your event inside of an event, which causes the need to re equip again. To fix this, make your event its own code block.

tool.Equipped:Connect(function(mouse)
    equip:Play()

    mouse.Button1Down:Connect(function()
        light.Material = Enum.Material.Neon
        light.BrickColor = BrickColor.new"New yeller"
        pointlight.Enabled = not pointlight.Enabled
        click:Play()
    end) 
end)

tool.Unequipped:Connect(function() -- No mouse parameter! Common mistake to add it.
    -- code
end)

You shouldn’t assign Enum properties (such as material) with strings, but with enum.

Ad

Answer this question