How to stop a "mouse.move" function from outside

hello, i need some help, im trying to stop a mouse.move function from outside of it., the function also stack everytime i equip the tool…

here the code:

script.Parent.Equipped:Connect(function() --i want the mouse.move function to run alone and not to clone itself everytime i equip the tool
    mouse.Move:Connect(function()
        print("move")
    end)
end)

script.Parent.Unequipped:Connect(function()
	--i want to stop the mouse.move function here, because it still printing "move" when i move the mouse even if the tool is unequipped
end)

Just make function’s variable.

Disconnects when unequipped.

1 Like
local mouseConnection = nil

script.Parent.Equipped:Connect(function()
    mouseConnection = mouse.Move:Connect(function()
        print("move")
    end)
end)

script.Parent.Unequipped:Connect(function()
	mouseConnection:Disconnect()
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.