Exit a VehicleSeat to a designated position

Do you notice that feature in Jailbreak where you exit the vehicle by pressing E or spacebar and spawns you on the side of the vehicle? That’s what I’m trying to do… and I don’t want its script to be outside of the VehicleSeat or the model.

Problem 1 - I only know how to make players get in the vehicle by interacting with a keybind via ProximityPrompt.
Problem 2 - The vehicles’ body has CanCollide enabled, that’s why I made this topic.

Reference 1 - A guy by the name of Okeanskiy made a script of this, but the problem is that the script is in a separate group/folder and it doesn’t make you exit the vehicle in a designated position.

Here’s his video: Enter a Car with E Key! - 2019 Scripting Tutorial (Keybind with UserInputService) - YouTube

Reference 2 - There’s this free model vehicle created by Roblox that has this feature, but the problem is that I can’t find the exact lines within the scripts that execute this feature.

Model: SUV - Roblox


When the player jump out the car you can set his HumanoidRootPart’s CFrame as the vehicle seat’s CFrame but by subtracting a certain amount of studs from the x-axis.

For example:

player.Character:WaitForChild("HumanoidRootPart").CFrame = VehicleSeat.CFrame - CFrame.new(5, 0, 0)

I see, but how can I do that without adding another script to another group/folder like StarterCharacterScripts?

When it comes to keybinds, the LocalPlayer gets in the way causing me to create another script within the StarterCharacterScripts folder.

Do you want do it in a Script into the car model?

If you are using a ProximityPrompt you can do this:


Yeah, that’s what I’m trying to do, but I think it’s impossible to do so.

Using this method you can create the variable of player so you can use it to do what I said in the first comment.

So basically, all I have to do is copy the line of code from your first comment and paste it inside the function?

local seat = --make the variable of the seat

    if not player.Character:WaitForChild(humanoid).seated then
        player.Character:WaitForChild("HumanoidRootPart"). CFrame = seat.CFrame - CFrame.new(5, 0, 0)

It gave me an error saying “attempt to index nil with ‘WaitForChild’”. I checked it out and I noticed that ‘humanoid’ is underlined. How do I fix this?

I pasted the lines of code inside a server script that executes the ProximityPrompt, and I assume that pasting it in a server script is the cause of this error.

Oh I’m sorry you must put it into “” and it must be Humanoid and not humanoid. I wrote it on phone :confused:

1 Like

It still gave me the same error…

So you’re wanting to get out at a designated position? Firstly, do you already have code set up to enter a seat? What you could do is make it detect changes to the Occupant property of the seat, which either contaisn the humanoid of who is sitting on the seat or nil if no one is sitting. You can have it store the occupant currently sitting, and when it becomes nil, get the former occupant, and CFrame team relating to either the RightVector, UpVector, or LookVector depending on the oritentation of the seat’s faces. A basis of what’d you want would be this

local seat = --Your seat

local formerOccupant

	local hum = seat.Occupant
	if hum then
		formerOccupant = hum.Parent
	elseif not hum and formerOccupant and formerOccupant:FindFirstChild("HumanoidRootPart") then
		formerOccupant.HumanoidRootPart.CFrame = seat.CFrame.RightVector * -5
        formerOccupant = nil

How this works is this

If there’s an occupant, store it in a variable, and if there’s no more occupant and the former one had a humanoidrootpart, set the CFrame of the rootpart to the RightVector multipled by 5 studs. This is how I believe it’s done, you will have to change RightVector to LookVector or UpVector if you are not being set to the left or right

It gave me another error saying ‘invalid argument #3 (CFrame expected, got Vector3)

Oh wait I forgot RightVector returns a Vector3, change this

formerOccupant.HumanoidRootPart.CFrame = seat.CFrame.RightVector * 5

To this

formerOccupant.HumanoidRootPart.CFrame = CFrame.new(seat.CFrame.RightVector * 5)

It worked, but the vehicle flung to the 4th dimension.

I think you have to increase the 5 then, try some trial and error to see what works

I managed to fix that problem with ‘wait(0.1)’, but it made me get off the car on the right side and it’s too offset. I’m really new to CFrames, so I don’t really know how it works.

If you want it to make it teleport you to the left side, multiply with a negative number. In my case I did 5, if you wanted it to teleport you to left side, do -5