Hello, I'm trying to change the character's position to something else right when it spawns in, but something else seems to be setting it after I change it.
Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) print(character.Name .. " has spawned"); local rig = character or character.player.CharacterAdded:Wait(); rig.HumanoidRootPart.CFrame = CFrame.new(500,500,500); print (rig.HumanoidRootPart.CFrame); end) end)
This prints out that the CFrame is equal to (500, 500, 500, 1, 0, 0, 0, 1, 0, 0, 0, 1), but then it changes to something like (0, 107, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1).
Understand how the Character spawns in first.
If the game does not have a set spawn point (i.e. via SpawnLocation), the Character will spawn a certain amount of studs along the Y axis above the point (0, 0, 0). In your case, that happens to be 107 studs above (0, 0, 0) along the Y axis. Because you're setting the CFrame before the Character completely spawns in, the CFrame is set first and then reset to the default CFrame assuming that there is no spawn point that the developer had set before the game ran.
To fix the problem, all you need to do is add a wait()
:
wait(0.1) local rig = character character.HumanoidRootPart.CFrame = CFrame.new(500, 500, 500) print(character.HumanoidRootPart.CFrame)
Somethin about vector3 gets in my head
I don't use cframe for spawning I use Position if you change it to the (untested) following
Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) print(character.Name .. " has spawned"); local rig = character or character.player.CharacterAdded:Wait(); rig.HumanoidRootPart.Position = Vector3.new(500,500,500); print (rig.HumanoidRootPart.CFrame); end) end)
it should work...