I’m trying to programmatically sit a user in a seat when they join the server, however, I can’t get them to sit properly.
This is what happens upon me joining and my character being added (this does not occur if I reset my character sometime after joining the game):
I’m assuming this might have something to do with the animation for sitting not being loaded yet. If this is the case, how can I be sure that the sit animation has loaded before calling seat:Sit()?
Code:
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local humanoid = char:WaitForChild('Humanoid');
humanoid.StateChanged:Connect(function(state)
if state == Enum.HumanoidStateType.Running then
ApplicantSeat:Sit(humanoid);
humanoid.JumpPower = 0;
humanoid.WalkSpeed = 0;
end;
end);
end);
end);
I forgot to mention in the OP, but I did try a wait(1) which did work (wait() on its own did not), however, I try to avoid waits whenever I can in my code. The fact that I need to wait is telling me that there’s likely something that hasn’t loaded yet, but I’m not sure what.
repeat
ApplicantSeat:Sit(humanoid)
until humanoid:GetState() == Enum.HumanoidStateType.Seated
While the use of a wait(1) may work, it’s bad practice to fix things that way as it is likely to be unreliable and you are much better to use a condition to make sure what you want to happen actually happens.
I tried this, however, when the humanoid is in the standing/sitting position (screenshot in OP), the humanoid state type is equal to seated, even though it doesn’t appear to be “seated” necessarily
I tried this, and what’s interesting is that even though the sitting animation doesn’t appear to be playing, GetPlayingAnimationTracks() still returns the sitting animation as one of the animation tracks that is being played
Another option is to have the client fire a remote event when they’ve loaded into the game fully / have their character loaded in properly. You’d then wait for that event to be fired first before doing the sitting.
Can you use the sit method from the client? That might be cleaner than using remote events as well.