lets say there's a player named Amxaso1. His stats are saved through DataStore. How would I script it so that it prints Amxaso1's stats when the server first starts?
How do I find out a specific player's stats with a script using datastore?
1 answer
A data store key for each player generally look something like
"Player-" .. player.UserId
So what you can do is something like this
print(pcall(yourDataStore.GetAsync, yourDataStore, "Player-" .. player.UserId));
And it should print their data. You can retrieve their user ID with the player.UserId property if you need this while they are in game.
If you need to access the data even when they are not in the game use Players:GetUserIdFromNameAsync(username) to get the player's ID from their name.
E.g. Players:GetUserIdFromNameAsync("incapaxx") would result in 129574502 since my ID is that number.
Note that this function sends web requests so it is recommended you wrap in pcall, since you cannot guarantee web requests will always be successful and it also errors if no account with the name username exists.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
follow when posting a question https://scriptinghelpers.org/help/how-post-good-questions-answers