Teleporting a player will kill them

So, I am trying to create a script that will teleport the player
when he touches a certain block in-game. Pretty easy right?
I don’t think it should be hard to do, but for some reason the game decides
to kill the player after moving them to the given location

the script i use:

local door = script.Parent
door.Touched:Connect(function(player)
	if player.Character.HumanoidRootPart then
		player.Character.HumanoidRootPart.CFrame = CFrame.new(-1183.74, 759.296, -589.548)
	end
end)

I have tried some solutions from already existing topics on the internet, have watched
some tutorials about onTouch and Touch events but sadly enough, they didn’t solve my
problem, also tried adding a statement that would change the player’s health after being moved,
I tried working with parts or spawns instead of CFrame/Vector3

solutions I already tried:

localteleportpart = script.Parent -- The part you want to teleport the player

teleportpart.Touched:Connect(function(hit)
   if hit.Parent.HumaniodRootPart then
       hit.Parent.HumanoidRootPart.Position =  Vector3. new(0,0,0) -- What ever X,Y,Z you want`
   end
end)
place = CFrame.new(0,0,0)--where you want the player to go when touched
script.Parent.Touched:Connect(function(p)
local humanoid = p.Parent:FindFirstChild("Humanoid")
if (humanoid ~nil) then
humanoid.Torso.CFrame = place
end
end)

^ this one didn’t work as i’m working with R15 and this was made for R6

I am pretty new to all this so I would defenitely appreciate it
if explenations can be kept simple, I’m still learning all the terms used on this forum :slight_smile:

(I prefer explanation before scripts are given out as I’m still learning and don’t want to lean on others too much)

do that, but replace position with CFrame

You can use SetPrimaryPartCFrame instead of directly changing the character’s humanoidrootpart.

local Door = script.Parent

Door.Touched:Connect(function(Hit)
	local Character = Hit.Parent
	local Humanoid = Character:FindFirstChild("Humanoid")
	if Character ~= nil then -- Checks if the Character doesn't equal nil
		if Humanoid ~= nil then --Checks if the Character has a humaniod
			if Character.PrimaryPart ~= nil then  --Checks if the Character's PrimaryPart (HumanoidRootPart) doesn't equal nil
				Character:SetPrimaryPartCFrame(CFrame.new(-1183.74, 759.296, -589.548))
			end
		end
	end
end)

This method doesn’t break the character’s joints, (Breaking the joints will cause the player who was teleported to die), and will safely move the player’s position to the CFrame

If you want to know more about SetPrimaryPartCFrame, you can click here

You could also use MoveTo instead of SetPrimaryPartCFrame, however MoveTo requires a Vector3 rather than a CFrame wont always put the player in the proper place if there’s a part in the way.

local Door = script.Parent

Door.Touched:Connect(function(Hit)
	local Character = Hit.Parent
	local Humanoid = Character:FindFirstChild("Humanoid")
	if Character ~= nil then -- Checks if the Character doesn't equal nil
		if Humanoid ~= nil then --Checks if the Character has a humaniod
			if Character.PrimaryPart ~= nil then  --Checks if the Character's PrimaryPart (HumanoidRootPart) doesn't equal nil
				Character:MoveTo(Vector3.new(-1183.74, 759.296, -589.548))
			end
		end
	end
end)

local door = script.Parent
door.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
hit.Parent.HumanoidRootPart.CFrame = CFrame.new(-1183.74, 759.296,-589.548)
end
end)

Setting the CFrame of the HRP shouldn’t cause any joints to break. There’s probably something else in the game that is killing the player.

Lots of misinformation being spread here.

The correct way is to use the Model:MoveTo() function. It’s the cleanest and most efficient way to do what you are trying to do.

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()

local Position = Vector3.new(0,0,0)

Character:MoveTo(Position)
1 Like

Its quite unfortunate but i have already tried this, it would give me
an error instead of teleporting

that error being:
“HumanoidRootPart is not a valid member of Model”

You should verify that whatever touched the teleporter is actually a player and not some debris or whatever.

door.Touched:Connect(function(part)
	local player = game.Players:GetPlayerFromCharacter(part.Parent)
	local hrp = player and player.Character:FindFirstChild("HumanoidRootPart")
	if (hrp) then
		-- do your stuff
	end
end)

If you use HumanoidRootPart.CFrame will Tp your player to the position that you want

this works indeed, i have used your code right now
and added my stuff in it as mentioned in the code block.
I’ll be marking this as a solution.

all are friendly thanked for the help and explanations though :smiley: