How to make the proximityprompt sit script work to leave the seat too

Hello im trying to make a press f to enter and leave a car so i took the proximity prompt script to sit a seat, and i was wondering how i could do it to leave the car too, i thought in moving humanoidrootpart to the side of the car but it doesnt work, idk what to do.

heres the script

local proximityPrompt = script.Parent

local seat = proximityPrompt.Parent

seat:GetPropertyChangedSignal("Occupant"):Connect(function()

if seat.Occupant then

proximityPrompt.Enabled = false

else

proximityPrompt.Enabled = true

end

end)

proximityPrompt.Triggered:Connect(function(player)

seat:Sit(player.Character.Humanoid)

end)

First we have to check if the player is sitting, if the player is we force them to sit, if the player isn’t we make them jump

  • Before the player jumps we make their jumppower 0 or close to 0 so the player will not leap up. Instead will just stand up.

So I will dispose of the script at the start.

At the start of the proximity prompt triggering we have to check if the character and humanoid are valid else the script will error and we dont want that.

local proximityPrompt = script.Parent

local seat = proximityPrompt.Parent

proximityPrompt.Triggered:Connect(function(player)
   if player.Character and player.Character:FindFirstChild("Humanoid") then
      local Humanoid = player.Character.Humanoid
      if Humanoid.SeatPart == seat then
         Humanoid.JumpPower = 0
         -- If this does not work change the jumppower to >0 else fire an event to the player's client so they jump.
         Humanoid.Jump = true 

         Humanoid.JumpPower = 0
      elseif not seat.Occupant then
         seat:Sit(Humanoid)
      end
   end
end)

so the car has the cancollide enabled so when i jump the player cant pass the roof, so there is another way of the player leave the vehicle, like teleporting him to the side of it?

Okay so I think you meant that the player will be stuck in the vehicle if he would just jump out from it. Instead what you could do is have a part, make it massless, not collidable and transparent then you want to set the characters’s root to the part, so it would be:

Player.Character.PrimaryPart.CFrame = ExitPart.CFrame

or

Player.Character:SetPrimaryPartCFrame(ExitPart.CFrame)

Both should work, you would put this after the player jumps.

I edited the previous message as I forgot to add that another player can not sit on a seat if it is already occupied.

If you want to move the player always above the car then you would do something like so:

-- The Vector3.new(0, Offset, 0) part will be the offset of where the player appears when leaving the car,
-- If you want the player to appear higher than change the Y of the Vector3 towards the desired offset.
Player.Character:SetPrimaryPartCFrame(Player.Character:GetPrimaryPartCFrame() + Vector3.new(0, 4, 0))

Same would work for:

-- Variable += Value 
-- means Variable = (Value) + Variable
Player.Character.PrimaryPart.CFrame += Vector3.new(0, 4, 0)

man still not working, now the character dont even jump, and im pretty sure i didnt do anything wrong

local proximityPrompt = script.Parent

local seat = proximityPrompt.Parent

proximityPrompt.Triggered:Connect(function(player)
	if player.Character and player.Character:FindFirstChild("Humanoid") then
		local Humanoid = player.Character.Humanoid
		if Humanoid.SeatPart == seat then
			Humanoid.JumpPower = 0
			-- If this does not work change the jumppower to >0 else fire an event to the player's client so they jump.
			Humanoid.Jump = true 
			player.Character:SetPrimaryPartCFrame(player.Character:GetPrimaryPartCFrame() + Vector3.new(0, 4, 0))
			Humanoid.JumpPower = 0
		elseif not seat.Occupant then
			seat:Sit(Humanoid)
			proximityPrompt.Enabled = false
		end
	end
end)

Okay so what you would need to do is run the jumping out client sidedly.
You can do this by having a local script referencing the proximity prompt (which is the fastest) or have a local script fire on an event (which has twice the ping delay).

Then the client script would need to use the same code for jumping the player out:

Humanoid.JumpPower = 0
Humanoid.Jump = true 
player.Character:SetPrimaryPartCFrame(player.Character:GetPrimaryPartCFrame() + Vector3.new(0, 4, 0))
Humanoid.JumpPower = 0

And basically have it fire in a function when the player uses the proximity prompt and is sitting on the specified seat or on a RemoteEvent.

I need to do all of this just to enter and leave the vehicle?? man roblox really need to make something easier

Else you can make the whole script client-sided which makes it a lot easier to do, but you would need to have an if statement checking if the player who fired the proximity prompt is the local player or not.

-- inside a function:
if playerWhoFired = game:GetService("Players").LocalPlayer then
   -- Code
end

Transfering the script to the client would make it so that the client has less delay, but any exploits are able to influence this, so note that. As any exploiter is able to influence the client and able to send events through RemoteEvents, but this is no issue as this will probably not be in the favour of the exploiter to delete or tinker with the script. Instead they could decompile it and read it.

but what this would solve, because the player still cant get out of the car

This is very inefficient. Seats have welds for the player to sit on them, and breaking the weld would make them stand. I’m not sure why you would set the JumpPower to 0 and CFrame the character, but if it works it works. For entering the seat, all you have to do is call the :Sit() function on the seat.

it doesnt work, i just want to make like jailbreak, you press f to enter the vehicle then you press f again to leave (the player is teleported to the side of the car)

Ah. For that, you could do the same thing, but then also teleport the player to the side of the car by adding a Vector3 offset to the seats CFrame, or a predefined offset.

when i add an else statement on the proximityprompt the second thing doesnt work, like when i just added to the player to leave the car, it worked

proximityPrompt.Triggered:Connect(function(player)
	seat:Sit(nil)
	player.Character.HumanoidRootPart.CFrame = player.Character.HumanoidRootPart.CFrame + Vector3.new(0, 0, 5) 
end)

but when i put to seat then else then make the script to leave only the enter thing works

I believe thats an issue with your if statement. Try checking if the humanoid is sitting in the same seat with the SeatPart property of the humanoid, and if so, jump. If not, seat them in the seat if the seat is empty.

how i can do that??? its like humanoid.seatpart or something

i did something like this and its not working but like theres no problem with it i think

proximityPrompt.Triggered:Connect(function(player)
	if player.Character.Humanoid == false then
		seat:Sit(nil)
		player.Character.HumanoidRootPart.CFrame = player.Character.HumanoidRootPart.CFrame + Vector3.new(0, 0, 5)
	else
		seat:Sit(player.Character.Humasnoid)
	end 
end)

You want to check if player.Character.Humanoid.SeatPart == Seat, and then if so run the code to make the player exit. in the else statement, you want to check elseif Seat.Occupant == nil so that players cant go in the seat if its already in use, and then sit the players humanoid.

so i tried what you said and it still only works for entering the car, probably something to do with the way im trying to get the player out of the car, but im not sure

proximityPrompt.Triggered:Connect(function(player)
	if player.Character.Humanoid.SeatPart == seat then
		player.Character.HumanoidRootPart.CFrame = player.Character.HumanoidRootPart.CFrame + Vector3.new(0,0,5)
	elseif seat.Occupant == nil then
		seat:Sit(player.Character.Humanoid)
	end
end)

Do you get it work? because i want to make it work too, i got to work in the end but the car part has collidable and the player cant go out

The Script …

local seat = script.Parent
local exitLocationAttachment = seat.ExitLocationAttachment
local prompt = Instance.new("ProximityPrompt", seat)
prompt.ActionText = "Sit Down"
prompt.ObjectText = "Seat"
prompt.Enabled = true

local function Stand(character)
	local humanoid = character:WaitForChild("Humanoid")
	humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
	seat.SeatWeld:Destroy()	task.wait(0.01)
	character:PivotTo(exitLocationAttachment.WorldCFrame)
	prompt.ActionText = "Sit Down"
end

local function Sit(character)
	local humanoid = character:WaitForChild("Humanoid")
	seat:Sit(humanoid) prompt.ActionText = "Stand Up"
end

prompt.Triggered:Connect(function(player)
	local character = player.Character
	if seat.Occupant then
		Stand(character)
	else Sit(character)
	end
end)

This uses an Attachment to set the exit spot.
( I learned how to make this myself from studying how toolbox car models work, OMG )
The Setup SitStandPrompt.rbxm (3.9 KB) ← Works well but, it needs that no jump added.

I do this with a key and not the prompt myself as I really don’t like that prompt visable while sitting.