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

When I unequiped my tool the click multiplies, how do i fix it?(Fixed thx people)

Asked by
adcd433 12
3 years ago
Edited 3 years ago

This is in local Script

local Tool = script.Parent

local UserInputService = game:GetService("UserInputService")

Tool.Equipped:Connect(function()

UserInputService.InputBegan:Connect(function(Input)

    if Input.UserInputType == Enum.UserInputType.MouseButton1 then

        print("mouse down")

    end

end)

end)

every time i re-equipped the tool, the click multiplies like the first time i equip and click it adds one to the counter when i re-equipped and click it adds 2 to the counter pls help

0
why not just use Tool.Activated 0msh 333 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

it happens bc you are adding an event inside an event, means the second time the Equipped event gets called, you have that function connected twice to InputBegan, so it fires twice, either disconnect the event on unequip or move it out the equip event and add a bool to the if of the inputbegan event that you set to true on equip and false dequip or like the person said in the comments use the tool.Activated event instead of inputbegan

0
ok thx adcd433 12 — 3y
0
you can mark it as solved if it fixed ur problem VerdommeMan 1479 — 3y
Ad
Log in to vote
0
Answered by
adcd433 12
3 years ago

i think the reason is everytime i equipped the tool the UserInput Service fire and looks every second and when i re-equipped it the action doesnt unbind i think

Answer this question