Having trouble unsitting and moving the player out of a car

So im trying to design my own custom vehicle system and I have running into issues with unsitting the player outside of the car.

I am trying to design this a way where the car is a solid object where characters cant just walk inside it, and just uses interaction to sit, where as unsitting the player is binded to the space key.

The above video shows some weird problems with moving and unsitting the player outside of the car.

Not sure where the jumping is coming from as the humanoids JumpHeight and JumpPower is set to 0.

When a player gets out of the video, the network ownership of the vehicle is immediately set to the server, and then the following code is ran to unsit and move the player out of the vehicle:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remote = ReplicatedStorage:WaitForChild("Remotes").Unsit

Remote.OnServerInvoke = function(Player)
	local Character = Player.Character
	if Character then
		local Humanoid: Humanoid = Character:FindFirstChild("Humanoid")
		local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
		
		if Humanoid and HumanoidRootPart then
			if Humanoid.Sit and Humanoid.SeatPart and HumanoidRootPart.AssemblyLinearVelocity.Magnitude < 25 then
				local OffsetDirection = (Humanoid.SeatPart:GetAttribute("ExitDirection") or Vector3.new(0, 0, 0)) * 3

				Humanoid.Sit = false

				repeat task.wait() until not Humanoid.SeatPart

				local CharPivot = Character:GetPivot()
				local FutureCFrame = CharPivot * CFrame.new(OffsetDirection.X, 0, 0)

				Character:PivotTo(FutureCFrame)
			end
		end
	end
	
	return false
end

Anyone know how a solution or a way to make a smooth and reliable version of this where the character physics wont interfere with things?

I’m not quite sure how other car games handle this so effortlessly.

Many thanks!

2 Likes

You could try anchoring the character for just a little while before and after the PivotTo?

Have you tried disabling the humanoid state for jumping? Also unless the jumpheight is set to 0 in the place’s settings and you are changing it through local script, by giving the network ownership of the character to the server, it just might be overriding the jumpheight to a server default on that humanoid.

Another thought is maybe just scrap the server character Pivoting and try move it into a client script so you don’t have to fiddle with the character network ownership at all?

For some odd reason it didn’t even attempt to move the character when i tried this

1 Like

You could user userinputservice to block out the spacebar

Oh, i should’ve mentioned the networking was done on the vehicle, not the character, but I tried that too and got no luck…

Originally this was client sided, but I had problems where the character would push the car when they teleported out… Some weird stuff with collisions is occurring on the server side it seems.

Tried that too. No luck… I think the “jumping” is just the character hitting something and being flung slightly upwards somehow, cause there’s no way the humanoid can jump at all.

Im just wondering how other games handle it so flawlessly…

You could just teleport the player outside the vehicle

That is what im trying to achieve. Seamlessly teleporting the player outside the vehicle without any weird interfering with the collosions going on with the vehicle itself. The car has lots of solid hitboxes.

what happens if you were to put the exit position offset to some higher number? So the character wouldn’t be able to touch anything while exiting, would it still “jump”?

Or maybe try to make a new collision group for both the car and the player model, and make them not collide with each to and see if that stops the “jumping”.

This way you can determine if its really being flung by something or if it’s actually the humanoid’s fault.

Great question. Yeah it seems to still do the jump, which is odd since I never had this issue when I ran this code client sided. It might actually be something weird with the humanoid going on.

EDIT Made an interesting observation. I turned on the inner collision for the car (so players cannot walk in, which is what I planned on having anyways) and even when teleporting a far, it still seems to push the car around.

This example uses the client sided code:

Are you using Humanoid seat for the character? I don’t really have much experience with them cuz I don’t like to rely on roblox’s built-in instances when I don’t have to, but you could try just welding the player’s character to the car instead.

I am using roblox’s default vehicle seats, which create a weld when you sit down. I tried instead manually destroying the weld and then pivoting the character, but that doesn’t seem to work on the same frame… The character just ends up standing inside the car.

However, you gave me an idea with collision groups. I wonder if its possible to disable character-to-vehicle collision on the server, but then on the client have the collisions enabled? It would fix any server side collision problems.

Might end up trying that as well.
EDIT: Nevermind, forgot that API can be only used on the server

1 Like

What if you try adding a delay between them, overdo it with like one-second delays (just to see if they work and it’s some sort of timing issue)

So whenever you destroy the weld, wait for 1 second, then pivot the character.

Ended up trying this, and having a delay just removes the seamless teleportation. The player teleports on top of the car upon SeatWeld removal, and then i had to have a 0.1s wait to the teleport the player to the side of the car.

This is most certainly not ideal for a game. The client side teleportation seems to be the best results, but and I can’t really figure out how to fix the server side issues, because this is what is happening on the server side:

They don’t… place an attachment outside the door then PivotTo() that.

This is basically what Im already doing… Did you go over my code? it is already using PivotTo.

I even tried pivoting to an attachment outside the car and im still getting the same problem

Move it farther out until it works

These may help…
Actually manually place an offset attachment or a welded part by the door and use that to PivotTo().

Stop the jump; Humanoid.Jump = false

local rns = game:GetService(“RunService”)
rns.Stepped:Wait() vs task.wait() in your loop.

Use task.wait(0.33) possibly at transitions or maybe a rns.Stepped:Wait()
There is a timing that needs to be done in order, use them as fine-tuning.

I can move it as far out as possible and the player still moves the car on the server side. Its as if the player on the server end doesn’t get immediately teleported and stays for a bit, its weird…

Have you tried NoCollisionConstraints? It looks like when your character gets up from the seat theyre hitting their head on the top of the car which is causing them to do that iconic roblox fling.

You could also try just setting the characters rootpart velocity to 0 when they get out of the car.

Another thing you could try is disabling the humanoids physics state