Seat:Sit seats player standing up

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):
image

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);

Hello m_xddle,

I have tried your script and I got the same issue, I also tried it with a wait() and that solved the issue. Is it possible to have a wait()?

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
				wait()
				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.

I also don’t know what isn’t loaded but on this page you can see that they use RunService.Stepped:wait() to avoid things.

Wait a brief moment before teleporting, as Roblox will teleport the
player to their designated SpawnLocation (which we will override)

Tried this too, no improvement still :confused:

Here I was standing like 2/10 times I used RunService.Stepped:Wait() , I can’t really help you sorry, maybe someone else can :wink:

1 Like

The same thing happened to me when, I’ll keep trying and update if I find something that works.

Couldn’t run into the issue myself (???) but, have you tried loading the animation on client when the state is changed to Seated using:

local sitAnimation = char.Humanoid:LoadAnimation(char:WaitForChild("Animate").sit.SitAnim)

And play it when necessary?
Maybe this could change something? :thinking:

1 Like

Perhaps something like:

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.

1 Like

Humanoid:LoadAnimation() is deprecated, it is now supposed to be done from Humanoid.Animator

2 Likes

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

Ah okay. Maybe a loop with humanoid:GetPlayingAnimationTracks() instead then

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

1 Like

Sometimes you have to wait, as you’ve found, but calling a simple wait(x) isn’t guaranteed to work. Try this:

That’s frustrating.

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.