Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I find out a specific player's stats with a script using datastore?

Asked by
steelflix -12
5 years ago

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?

1 answer

Log in to vote
0
Answered by 5 years ago

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.

Ad

Answer this question