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

How to anchor the player when they land after jumping?

As the titles says Im trying to make it so the player becomes anchored after they land from a jump. Instead the script only has a jump cooldown and does not anchor, I don't know where I went wrong. Here is my failed attempt.

local character = script.Parent

local JUMP_DEBOUNCE = 5

local root = character:WaitForChild("HumanoidRootPart")
local humanoid = character:WaitForChild("Humanoid")

local isJumping = root.Anchored

humanoid.StateChanged:Connect(function(oldState, newState)
	if newState == Enum.HumanoidStateType.Jumping then
		if not isJumping then
			isJumping = true
			humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
		end
	elseif newState == Enum.HumanoidStateType.Landed then
		if isJumping then
			isJumping = false
			wait(JUMP_DEBOUNCE)
			humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
		end
	end
end)

1 answer

✓ Accepted answer

You did a simple mistake. You must anchor it after it lands not when it jumps Here is the script that worked for me

local character = script.Parent

local JUMP_DEBOUNCE = 5

local root = character:WaitForChild("HumanoidRootPart")
local humanoid = character:WaitForChild("Humanoid")

local isJumping = root.Anchored

humanoid.StateChanged:Connect(function(oldState, newState)
	if newState == Enum.HumanoidStateType.Jumping then
		if isJumping then
			root.Anchored = false
		end
	elseif newState == Enum.HumanoidStateType.Landed then
		if not isJumping then
			wait(JUMP_DEBOUNCE)
			root.Anchored = true
			humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
		end
	end
end)

When you anchor the root part you cannot walk, jump, and run. It's like platformstand.

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