I’m trying to save the location of each player when they leave the game, and have them spawn in the same location, but I don’t really have any idea of how to do this. I’ve been trying to program this through DataStores, but I’m not having any luck. Any advice would be greatly appreciated.
Just dont save it as a vector3 or as a cframe. Thats a start. Can try using {cf:GetComponents()}
I would save the player’s HumanoidRootPart CFrame to a dedicated player position DataStore and plug the data in to the character’s HRP when they return to the game.
Edit: I see, I wasn’t sure about the DataStore limits on CFrame. Components are pretty long so if it’s not important to record the player’s precise rotation then I would focus on their bearing or just their XYZ position.
You use cf:components to serialize the data so that the datastore can handle it, then when they log in again, and you read the data, reconstruct the cframe with the appropriate constructor, then use character:setprimarypartcframe(cframe)
CFrame.new(unpack(componentlist))
The datastore limit is more than enough. You could probably store 2 thousands of these, even if they are long floats.
Answered above. Just want to throw a tip around - you should probably only save locations when a player is on the ground. It might be a little troublesome if someone comes back spawned high up in the air.
As others have said, you should take apart the player’s Position / CFrame since you can’t save CFrames and Vector3s in a DataStore, only primitives such as numbers and strings (and tables).
You should only save their X Y Z coordinates because their orientation won’t be important, and this will simplify your code when you load the data. You could also safely round the numbers to one decimal place to save space, but this is not necessary unless you’re really pushing the limits.
Orientation might be important so that they are in the exact same spot and if for example they are in a tight space they cannot glitch out of bounds.
The default character has only ~2x2x1 studs that matter. In most cases rotation will not be an issue, but it could depend on the game.