Teleporting Someone's Character Problem

Hi all,

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.

How can I fix this? Thanks in advance.

2 Likes

Hmm is it because your setting the humanoids jump to true directly shouldn’t you do:

humanoid:ChangeState(Enum.HumanoidStateType.Jumping)

1 Like

Unfortunately that made no difference, the player doesnt get teleported out

1 Like

Try setting humanoid.Sit = false, and waiting longer. You shouldn’t need the weld destruction code.

Then, run that code once and check properties of the target humanoid in the explorer.

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.

0.1s should be enough. Setting humanoid.Sit to false automatically destroys the weld.

1 Like

0.5s wasn’t enough when I tested it.

1 Like

Bump, I’m really clueless. I’ve tried so many things.