How to stop jump after anchoring and unanchoring the character?

Good day, I am currently working on an aim script where the character is anchored so as to make it stay in place, and to make the character face where the mouse is facing.

When I equip the tool, that’s where I anchor the character and where the aiming takes place. When I unequip it, it stops aiming and unanchors the character.

But the problem is that after unanchoring the character, the jump somehow still continues? I don’t want this, I just want the character to fall after “aiming”.

Here is the video of my problem and the code snippet:
https://streamable.com/zpjv6r

Inside the local script:

local player = game.Players.LocalPlayer

local isHolding = false
local mouseConnection

tool.Equipped:Connect(function()
	isHolding = true
	local character = player.Character or player.CharacterAdded:Wait()
	local rootPart = character:WaitForChild("HumanoidRootPart")

	--Anchor the character and add the mouse event.
	rootPart.Anchored = true
	mouseConnection = mouse.Move:Connect(function()
		if isHolding then
            --Rotate the character.
			rootPart.CFrame = CFrame.new(rootPart.Position, rootPart.Position + mouse.Hit.LookVector)
		end
	end)
end)

tool.Unequipped:Connect(function()
	isHolding = false
	local character = player.Character or player.CharacterAdded:Wait()
	local rootPart = character:WaitForChild("HumanoidRootPart")
	
	--Unanchor the character and disconnect the event.
	rootPart.Anchored = false
	mouseConnection:Disconnect()
end)

Anyone have any fixes for this? Again, I just want the character to fall right after he unequips the tool.

Have you tried changing the humanoids JumpPower to 0? This should fix the issue.

1 Like

I was actually purposefully jumping to show that the jump before equipping the tool still continues after I anchor and unanchor the character.

The problem still persists even after setting the humanoid’s jump power to 0.

There is probably a better way but maybe create force in the HumanoidRootPart to counter the jump?

1 Like

Set the humanoid root part velocity to zero, when anchored the part still retains it’s velocity so it goes up so this should fix it.

3 Likes

Thanks. I didn’t know it was that simple.

This shows the fixed aim system:
https://streamable.com/mxnokb

As you can see, the jump is now cancelled after the character gets unanchored.