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

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

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

1 comment

0

why not just use Tool.Activated

2 answers

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

2 comments

0

ok thx

0

you can mark it as solved if it fixed ur problem

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

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