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!
I don't think there is a way to edit an existing DataStore unless you use the DataStore Editor
plugin as of here.