Faulty vehicle exit script

  1. What do you want to achieve?
    A more reliable exit script.

  2. What is the issue?
    You’d get stuck in the vehicle for a short time; get stuck by accident.

  3. What solutions have you tried so far?
    I tried to teleport the HumanoidRootPart to an attachment upon jumping, but it still makes you stuck in the vehicle and I tried to make an A-Chassis plugin that’ll teleport you out of the vehicle by pressing a keybind, but it didn’t work.

here are the scripts that I tried so far:
• Video #1:

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	local hum = seat.Occupant

	if hum then
		formerOccupant = hum.Parent
	else
		wait()
		formerOccupant.HumanoidRootPart.CFrame = seat.CFrame + (seat.CFrame.RightVector * -2.8)
		formerOccupant = nil
	end
end)

• Video #2:

function exit()
	seat.Occupant.Parent.HumanoidRootPart.Position = seat.ExitAttachment.WorldPosition
	seat.Occupant.Parent.HumanoidRootPart.Orientation = seat.ExitAttachment.WorldOrientation
end

seat.ChildRemoved:Connect(exit)

• A-Chassis LocalScript:

local Character = game.Players.LocalPlayer.Character

UIS.InputBegan:Connect(function(i, focus)
	if focus == true then return end
	if i.KeyCode == Enum.KeyCode.F then
		Character.HumanoidRootPart.Position = car.DriveSeat.ExitAttachment.WorldPosition
	end
end)

What do you use to register the player leaving the seat and where’s it meant to put them?
I think what’s happening is there’s a very slight delay when the script notices the player has left the seat. I’m not sure where the car’s ExitAttachment position is in relation to the car.

1 Like

The attachment was placed far enough for the player to avoid clipping into the vehicle and I really want to get rid of that slight delay.
image

A workaround solution would be to make the player uncollidable with the car when they begin driving. If cancollide is turned off, I don’t think you’ll get any camera issues and you won’t notice it, in theory.
What registers the player leaving the seat? Is it them pressing F or jumping out?

Both scripts from video #1 and video #2 teleport the player by jumping out while the A-Chassis localscript teleports the player by pressing F, but it doesn’t work for some reason.

A-Chassis does that in their initialize script, so I don’t see the need to make the player uncollidable.

A player pressing F shouldn’t have a delay and it’s rather impolite to not work for us. Have you tried something like

if i.KeyCode == Enum.KeyCode.F then
Character.Humanoid.Jump = true
Character.HumanoidRootPart.Position = car.DriveSeat.ExitAttachment.WorldPosition
end

Yes. The jumping worked but the changing of the HumanoidRootPart’s position didn’t.

Have you tried not using the Attachment’s position?
Something like

Character.PrimaryPart.CFrame = Character.PrimaryPart.CFrame * CFrame.new(Vector3.new(5,0,0) -- Change this 
1 Like

Ok, it seems like the reason why the character can’t get off is that it didn’t get off the seat. Is there another way to make the player get off the seat without making it jump?

I think you can disable the seat by setting disable to true. I believe this ejects the player without making them jump. Make sure to put this line straight before teleporting them.

The VehicleSeat has disabled enabled so that no player can teleport inside the vehicle without the ProximityPrompt. I tried removing the SeatWeld, but it didn’t work out well.

Hacky, but you could turn off the player’s cancollide for a split second, then turn it back on, I think that would fix it? But I have had problems with turning limbs into cancollide false in the past, I might be wrong.

1 Like

Yeah don’t remove that weld. If you want to be fancy, you can do

Character.Humanoid.Sit = false
Character.PrimaryPart.CFrame = Character.PrimaryPart.CFrame * CFrame.new(Vector3.new(5,0,0)

That should work!

1 Like

It worked, but… What in the world is happening?

Beautiful! You got out the car in one piece!

2 Likes

I’m laughing way too hard at that.
Is it possible the player is being caught by another seat?
It looks like he’s meant to be on the left side, but while the car is entering 17 dimensions, he’s teleported to the right side of the car momentarily, appearing to be seated.

1 Like

All the seats have disabled enabled which doesn’t let the player get caught up on the other seats. I also set the X value to -5, and it flung me to the 4th dimension for a wee bit.

Try changing around with the value. Maybe try 10 then -10 and see what happens when you do that. It might be the Z value I don’t know.
It’s possible the character is clipping the car.
I can’t remember if I asked, but have you tried making the car uncollidable for that small period of time?

Changed it to 10 and -10, it flung me to the 4th dimension…