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:
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:
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.
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.
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.
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)
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.