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

Creating a key with Data Stores?

Asked by
Omarstein 100
10 years ago

Just a simple question, how could I create a key with Data Stores to a new player in-game?

2 answers

Log in to vote
0
Answered by 10 years ago

You cannot assigns data store keys to certain players like you can with data persistence, but you can do something like assign a key that has their username/userid.

For example:

ds=Game:GetService("DataStoreService"):GetDataStore("Users")

Game.Players.PlayerAdded:connect(function()
ds:SetAsync(tostring(player.userId),player.Name) --That would create a key with a name that is equal to their userId and make the key's value their username.
end)
0
So, even if they don't have a key, that would create a new key and assign a value to it? Omarstein 100 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

You can edit it so it matches what you want it to do.

DataStore = game:GetService("DataStoreService"):GetGlobalDataStore();

game.Players.PlayerAdded:connect(function(player)
    local keyName = player.userId .. "_keyname"; -- you should use their userid, incase they change their username
    local newValue = "new value"; --change this to the key's value

    DataStore:UpdateAsync(keyName,(function(oldValue) return newValue end));
end)

Answer this question