I want a player to spawn at a specific location in the world. When I try to move them during the CharacterAdded event, they teleport to a different location the following frame.
This is reproducible on a baseplate: CharacterAddedTeleport.rbxl (18.0 KB)
Code:
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(ch)
print("added")
ch:SetPrimaryPartCFrame(workspace.Spawn.CFrame)
print(ch.PrimaryPart.Position)
wait()
print(ch.PrimaryPart.Position)
end)
end)
Output:
added
-6.13999939, 2.75444603, -11.4400043
0, 103.710884, 0
The character teleports to a default spawn location the following frame. This behavior is very surprising. Is it possible for Roblox to move the character to the default spawn location before firing the CharacterAdded event?
It’s painful for me to handle delaying setting the character’s CFrame because if one of my scripts executes before that, the character being in the wrong location can incorrectly trigger game events. Any work around suggestions would be appreciated.