Correct usage of Humanoid:Sit()

Hi, I have been trying to make humanoid NPCs sit down with the following:

    Character.PrimaryPart.Anchored = false -- So we can move

    AnimateCharacter(Character, Character.Animate.sit.SitAnim, true) -- A function to play anims
    
    SeatPart:Sit(Character.Humanoid)
    Character.Humanoid:ChangeState(Enum.HumanoidStateType.Seated)

However, occasionally (about a third of the time), the humanoids do not animate, do not sit down and instead hover in the air where the seat was forever (even if the seat then moves). Am I doing something wrong?

1 Like

Maybe the AnimateCharacter function has some logical error.

The AnimateCharacter function:

local function AnimateCharacter(Character, Animation, direction)
	local ATracks = GetATracks(Character)

	--find the requested track
	local Requested
	for count = 2, #ATracks do
		if ATracks[count].Animation == Animation then
			Requested = ATracks[count]
		end
	end

	--if we haven't loaded this track yet
	if Requested == nil then
		Requested = Character.Humanoid.Animator:LoadAnimation(Animation)
		table.insert(ATracks, Requested) --add to table
	end

	--play it
	if direction == true or direction == nil then
		Requested:Play()
	else
		Requested:Stop()
	end
end

And the GetATracks function:

local function GetATracks(Character)
	for _, ATracks in ipairs(CharacterATracks)do
		if ATracks[1] == p then
			return ATracks
		end
	end

	--if there wasn't one
	local NewATracks = { Character }
	table.insert(CharacterATracks, NewATracks)
	return NewATracks
end

Both of these are quite old, and I think they predate this issue. I barely remember what they’re doing, anyway.

Could it be an animation replication error?

Just removed animation entirely, and the other issues described are still happening, so I don’t think that’s the root cause.

Do any errors print out at all?

Nope, no errors or anything, ever.