So I am trying to make a custom proximity prompt based enter/exit vehicle script. What’s supposed to happen is that if you interact with the proximity prompt, you get put into the vehicle and pressing space forces you to jump and teleports you outside of the vehicle. What is instead happening is that the enter system is working fine, but the exit vehicle script isn’t working.
Server Script:
local UIS = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")
local ExitCFrame = script.Parent.Parent.Body.ExitVehicleCFrame.CFrame
local Occupant
local PlayerFromCharacter
script.Parent:GetPropertyChangedSignal("Occupant"):Connect(function()
Occupant = script.Parent.Occupant
Occupant.JumpHeight = 0
PlayerFromCharacter = game.Players:GetPlayerFromCharacter(Occupant.Parent)
end)
-- ⚠️ The whole problem ⚠️
RS.VehicleFunctions.ExitVehicle.OnServerEvent:Connect(function(player)
if Occupant and PlayerFromCharacter and PlayerFromCharacter == player then
Occupant.JumpHeight = 7.4
Occupant.Jump = true
Occupant.Parent.HumanoidRootPart.CFrame = CFrame.new(0.317, 3.467, -24.795)
end
end)
Local Script in StarterPlayer < StaterPlayerScripts
local UIS = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
UIS.JumpRequest:Connect(function(input, gameProcessed)
RS.VehicleFunctions.ExitVehicle:FireServer(player)
end)
How the exiting system works is that a script using the UserInputService is in the StarterPlayerScripts and it fires a remote event when the player jumps. Then when the server scripts detects the event being fired, it makes sure that the occupant of the vehicle matches the person who fired the remote event. After that it sets the occupant’s jump height to 7.4, which is a part of the problem, and then teleports them outside of the vehicle, which is the other problem.
Thanks!
EDIT:
Everything started working, so if you wish to use it you may. I have only used it on A-Chassis but you may try it on others if you wish.
For A-Chassis, create a script in the drivers seat and paste in the below.
local RS = game:GetService("ReplicatedStorage")
local ExitCFrame = script.Parent.Parent.Body.Color.ExitVehicleCFrame
local Occupant
script.Parent:GetPropertyChangedSignal("Occupant"):Connect(function(player)
Occupant = script.Parent.Occupant
Occupant = Occupant
end)
print(ExitCFrame.CFrame)
-- ⚠️ The whole problem ⚠️
RS.VehicleFunctions.ExitVehicle.OnServerEvent:Connect(function(player)
if Occupant == player.Character.Humanoid then
task.wait(.1)
player.Character:PivotTo(path.to.cframepart:WaitForChild("ItemWithCFrame").CFrame)
player.Character.Humanoid.JumpHeight = 7.2
player.Character.Humanoid.Jump = true
print(player.Character)
end
end)
Then create a script in StarterPlayerScripts and paste the below.
local UIS = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
UIS.JumpRequest:Connect(function(input, gameProcessed)
RS.VehicleFunctions.ExitVehicle:FireServer(player)
end)
Finally, create a folder in ReplicatedStorage and name it VehicleFunctions, as well as put a remote event in that folder called ExitVehicle.
That’s it! You are done. Just make sure in the server script that you replace path.to.cframepart with the path to the CFrame Part and the ItemWithCFrame with the item that has the CFrame.