Hey all, I have an existing datastore containing player data that I want to add a new value too.
Here is the code I used. When I first coded this into my game, I created it with Points, Survivals, Level, and XP as the only values. Now that I have added the Colour value, it won't save/load to previously existing player data, presumably because I'm trying to update a value that does not exist in their datastore. (leaderstats is what appears on the leaderboard, and hiddenstats are stats that aren't public to others)
local Data = game:GetService('DataStoreService'):GetDataStore('Data0')
local prefix = 'user_'
game.Players.PlayerAdded:connect(function(player)
local leaderstats = player:WaitForChild("leaderstats")
local hiddenstats = player:WaitForChild("hiddenstats")
local points = leaderstats:WaitForChild("Points")
local survivals = hiddenstats:WaitForChild("Survivals")
local level = leaderstats:WaitForChild("Level")
local xp = hiddenstats:WaitForChild("XP")
local colour = hiddenstats:WaitForChild("Colour")
local plrData = Data:GetAsync(prefix .. tostring(player.UserId))
if plrData then
points.Value = plrData[1] or 0
survivals.Value = plrData[2] or 0
level.Value = plrData[3] or 1
xp.Value = plrData[4] or 0
colour.Value = plrData[5] or 7
else
Data:SetAsync(prefix .. tostring(player.UserId), {
points.Value,
survivals.Value,
level.Value,
xp.Value,
colour.Value
})
end
end)
game.Players.PlayerRemoving:connect(function(player)
Data:SetAsync(prefix .. tostring(player.UserId), {
player.leaderstats.Points.Value,
player.hiddenstats.Survivals.Value,
player.leaderstats.Level.Value,
player.hiddenstats.XP.Value,
player.hiddenstats.Colour.Value
})
end)
I think I understand the problem, but I'm not entirely sure how I could work this into my code. Any help or suggestions would be greatly appreciated!

4 comments
I downloaded the plugin and watched the tutorial, but the game won't even recognize my place ID, it just gives me an error 403 when I try to load in anything...
The plugin would help a lot with changing peoples data anyway, if I could get it to work, but I'm more looking for something I can work into my data script to 'update' someones data, so I don't have to do it manually every single time i add a new stat to the game
I don't think there is a proper way to update a datastore, cause it creates a new datastore when adding new stats.
I read some other forum posts of people doing it, I just wasn't sure as to how I could update my own script