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?
A data store key for each player generally look something like
lua
"Player-" .. player.UserId
So what you can do is something like this
lua
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.