Just a simple question, how could I create a key with Data Stores to a new player in-game?
COMMUNITY QUESTION
Creating a key with Data Stores?
2 answers
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)
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)
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
So, even if they don't have a key, that would create a new key and assign a value to it?