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.
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!
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)
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 :).