Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

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

Asked by 7 days ago
Edited 7 days 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 318 — 7d

2 answers

Log in to vote
0
Answered by 7 days ago
Edited 7 days 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 5 — 7d
0
you can mark it as solved if it fixed ur problem VerdommeMan 790 — 7d
Ad
Log in to vote
0
Answered by 7 days 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