How do you properly teleport a player out of a seat?

I want to teleport a seated player to a specific position/CFrame.

the things I tried:

1:

char:MoveTo(game.Workspace.Part.Position)  
--this only makes the character stand up. 

2:

char.HumanoidRootPart.CFrame = game.Workspace.Part.CFrame
--this makes the character teleport to the specific CFrame TOGETHER with the seat.

3:

char.Humanoid.Sit = false
wait()
char:MoveTo(game.Workspace.Part.Position)
--this is a good solution - the only problem is that MoveTo() is used:
--the problem with this is that if there are any obstacles (collidable or non-collidable), the character gets teleported on top of them

4:

char.Humanoid.Sit = false
wait(0.2) --seems reliable? turning this to just wait() is not reliable.
--repeat wait() until char.Humanoid.Sit == false is also not reliable. 
char.HumanoidRootPart.CFrame = game.Workspace.Part.CFrame	

My question:

What is the best and most reliable way to teleport a character out of a seat?

6 Likes

The first method is not a solution. It only shows that when using MoveTo() without unseating the character first, the character only stands up without teleporting to the position/CFrame.

I don’t really know if there is a best way to do it, but to prevent from the player sitting again, I would teleport them a couple studs infront of them.

char.Humanoid.Sit = false
wait(0.2) 
char.HumanoidRootPart.CFrame = char.HumanoidRootPart.CFrame * CFrame.new(Vector3.new(0, 0, -2)) -- offset, you gotta play around with this
-- moveto()
1 Like

Oh my bad, I didn’t u see stand the question properly.

The problem with this is that the wait(0.2) is not 100% reliable. At least not for me. There could be a situation where the wait(0.2) is not long enough for the weld to get destroyed properly resulting in the player teleporting to the CFrame together with the seat

2 Likes

Make a check then.

repeat wait() until char.Humanoid.Sit == false

I’ve tried spamming this over 100 times so far in studio, and it works fine 100% of the time. it shouldn’t cause any issue cause the check is made from the live server.

1 Like
repeat wait() until char.Humanoid.Sit == false

I tried this resulting in the player very rarely being teleported together with the seat.

2 Likes

and… isn’t that what you’re trying to achieve? I’m confused.

The seat must not teleport together with the character

1 Like

What about changing the HumanoidStateType?

char.Humanoid:ChangeState(Enum.HumanoidStateType.RunningNoPhysics) 
char.HumanoidRootPart.CFrame = workspace.Part.CFrame

by “very rarely”, do you mean that it still does happen?

Yes. I tried this once in a loop with 4 players resulting in 2 players being teleported correctly and 2 together with the seat.

1 Like

This makes the player teleport together with the seat

changing the state of the humanoid seems to have no effect at all when the character is sitting

Darn, I brainstormed a new idea though. How about setting the Seat’s Occupant to nil?

seat.Occupant = nil

If nil doesn’t work, try it with a placeholder Humanoid Instance

1 Like

Using this doesnt work at all.

seat.Occupant = nil

Using the code below works, but I get the same result as method 4. Not knowing how long the wait() has to be. Since wait() is too fast. But wait(0.2) not. So there may be cases where wait(0.2) could not be fast enough

game.Workspace.Seat:Sit(nil)
wait()
char.HumanoidRootPart.CFrame = game.Workspace.Part.CFrame
2 Likes

You can use GetPropertyChangedSignal for exactly when Sit changes:

char.Humanoid:GetPropertyChangedSignal("Sit"):Wait()
2 Likes

This doesn’t seems to work either… same problem as

repeat wait() until char.Humanoid.Sit == false

And for this I would need to use multiple scripts to teleport a player. One for the event and one for making the player stand up.

I’m really surprised that it’s so hard to reliably teleport a player out of a seat

2 Likes
script.Parent:GetPropertyChangedSignal("Occupant"):Connect(function()
	local Humanoid = script.Parent.Occupant
	if not Humanoid then
		return
	end
	connection = Humanoid.StateChanged:Connect(function(prevState, newState)
		if prevState == Enum.HumanoidStateType.Seated then
			Humanoid.Parent.HumanoidRootPart.CFrame = CFrame.new(0, 10, 0)
			connection:Disconnect()
		end
	end)
end)
2 Likes

Has anyone, you know, tried jumping a Humanoid off the seat or destroying the seat weld from the server first? The only way to remove a Humanoid from a seat?

1 Like

I’ve been told that destroying the SeatWeld causes problems, look at my reply here:

1 Like