Player not TP'ing out of car when told to

How do I fix this?

Code:

local seat = script.Parent
local player 
seat.ChildRemoved:connect(function(player)
    seat.ChildRemoved:connect(function(child)
local TP = script.Parent.Parent.Body.tpout
    player.Character.HumanoidRootPart.CFrame = CFrame.new(TP.Position)
    end)
    
end)

What it looks like:

( The grey brick is where the player is supposed to TP. )

2 Likes

Are you sure it’s not just getting stuck in it? It’s hard to see where you’re actually getting tp’d to because of the clip but it looks like you’re stuck in something.

Try setting the TP part to CanCollide = false and trying again.

Also what are the errors?

1 Like

The TP part is false, and has been false since the day it was inserted. It is the code, not the TP part. You are only getting stuck because the top of the car is cancollide on, this is supposed to TP the player out of the car, there are no errors.

1 Like

Thinking about it, you cannot do ChildRemoved on a Seat to determine if the occupant of the seat changes.

You’ll want to do Seat.Changed and check if the changed property is the Occupant, if it is then do your teleporting code.

I am pretty sure you can do ChildRemoved, you see when the player was invisible and it jumped out that was ChildRemoved.

What is your code to put the player into the seat?

Also, why do you have a child removed inside a child removed function? Remove one.

ChildRemoved wasn’t the issue. I fixed the code. I just added a setup for all of them, and some more.

new code:

local seat = script.Parent
local player
seat.ChildAdded:connect(function(child)
	if child.Name == "SeatWeld" then
		player = child.Part1.Parent
		local plr = child.Part1.Parent:GetChildren()
		end
end)
seat.ChildRemoved:connect(function(child)
	if child.Name == "SeatWeld" then
		local plar = player:GetChildren()
		for i=1,#plar do
	local TP = script.Parent.Parent.Body.tpout
	wait(.5)
	player.HumanoidRootPart.CFrame = CFrame.new(TP.Position)
	wait(.1)
	player.HumanoidRootPart.CFrame = CFrame.new(player.HumanoidRootPart)
	wait(.1)
			end
		end
	end)

3 Likes