Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why cannot this code teleport the player?

Because of the nature of my procedurally generated map, the player spawns under it. The problem is that whatever I try I can't get to teleport the player and he always falls into the void

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		print(char.Humanoid.Torso)
		local hum = char:WaitForChild("Humanoid")
		hum.Torso.CFrame = CFrame.new(Vector3.new(0,50,0))
	end)
end)

I actually can't understand why this code doesn't work, as it's almost identical to everything else I found online. I tried using both the RootPart and the Torso and simply nothing happens.

3 answers

✓ Accepted answer

The way I usually do something like this is use model:SetPrimaryPartCFrame(). It is a lot more consistent than trying to teleport the player via any of their body parts. The revised code would look something like this:

	game.Players.PlayerAdded:Connect(function(player)
	    player.CharacterAdded:Connect(function(char)
	        print(char.Humanoid.Torso)
		if char then 
			car:SetPrimaryPartCFrame(CFrame.new(Vector3.new(0, 50, 0)))
		end 
	    end)
	end)

This should work. If you want an alternative way of doing this, you should consider using SpawnPoints. Also, make sure to continually check if the character is actually there to make sure your code does not error.

I hope this helps!

3 comments

0

This didn't work either, and I don't know why, after the game loads map generation is over, so I'm not sure if it's lag or Studio acting up. At the end of the day I just made it so that a spawn is created. Thanks for the reply, I will now try to make a teleport GUI to see if it works then comment back.

0

The GUI works. I don't know what caused that ( probably the endless death loop, my best guess ). Thank you for the code!

0

No problem! I hate that sometimes you try so hard to make your code work and then lag or some other stupid issue comes up. I'm glad you figured it out!

ok i fixed it, btw u cant teleport player with humanoid so u need to use humanoidrootpart

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
        print(char.Humanoid.Torso)
        local hum = char:WaitForChild("HumanoidRootPart")
        hum.CFrame = CFrame.new(Vector3.new(0,50,0))
    end)
end)

2 comments

0

This doesn't seem to work either, and I don't know why, even after the map is generated it doesn't work, so it can't be because of lag

0

wat is ur script? local script or normal script, if its local script, it doesnt work

Don't use the humanoid when teleporting players. Instead, replace line 5 with something like:

char.HumanoidRootPart.CFrame = CFrame.new(0, 50, 0)

Unless your output specifically tells you to use Vector3, you can just put in the 3 numbers in the CFrame. I hope this helps :).

This discussion is preserved as it was. New answers, comments, and votes are closed.