I’m working on an eject system for a cops and robbers game. For some reason, the player stays inside the vehicle when they get ejected. I’m unsure of what is causing this problem.
Here’s the code excerpt:
local OccupantHumanoid = DriveSeat.Occupant
if OccupantHumanoid then
local EjectedPlayer = game.Players:GetPlayerFromCharacter(OccupantHumanoid.Parent)
if EjectedPlayer then
for _, weld in pairs(OccupantHumanoid.Parent.HumanoidRootPart:GetJoints()) do
if weld.Name == "SeatWeld" then
weld:Destroy()
end
end
OccupantHumanoid.Sit = false
OccupantHumanoid.Jump = true
task.wait()
task.spawn(function()
task.defer(workspace.PivotTo, EjectedPlayer.Character, DriveSeat.CFrame * CFrame.new(-5,3,0))
end)
return true
end
end
I have tried setting a longer wait (0.5) but that made no difference at all. The player stays inside the car when they are supposed to get out.
This is already in the code that I shared on the original post.
The car teleports along with the player and glitches it when I don’t destroy the welds.
This is what I’m doing currently since it works, but I’m looking for a solution to make the teleporting instant because waiting 1 second makes the gameplay feel unnatural.