The character does not spawn instantly when the player joins. You can detect when the character spawns using Player.CharacterAdded (when this fires, the character hasn’t fully loaded yet, but I think the HumanoidRootPart will already exist).
Also, math.random() gives a number, not a CFrame. The CFrame constructed in the code below is probably not what you want but I’m not sure what you are trying to do.
The characterAddedConnections table and the code in the end are used for avoiding memory leaks (avoiding data that is no longer needed staying in memory).
If I’ve understood correctly, connections (RBXScriptConnection objects) do not get garbage collected before they are disconnected. When an instance is destroyed, connections to its events are automatically disconnected. However, when a player leaves the game, the Player instance is not destroyed allthough it’s parented to nil. This means that the connections to the events of a Player instance are not automatically disconnected when the player leaves.
The table characterAddedConnections is for storing the connection until the player leaves so that it can be disconnected then (and it’s removed from the table after disconnecting it so that there are no references to it anymore).