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

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

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

✓ Accepted answer

###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.

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