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?
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.