So whenever I update my game with this DataStore script it sets every player's stats back to the default they first had.
DataStore = game:GetService("DataStoreService"):GetDataStore("Values")
game.Players.PlayerAdded:connect(function(plr)
local rank = Instance.new("StringValue", plr)
rank.Value = "Asteroid Recruit"
rank.Name = "Rank"
local mined = Instance.new("IntValue", plr)
mined.Value = 0
mined.Name = "Mined"
local save = "plr-"..plr.userId
local savedVals = DataStore:GetAsync(save)
if savedVals then
rank.Value = savedVals[1]
mined.Value = savedVals[2]
else
local val = {rank.Value, mined.Value}
DataStore:SetAsync(save, val[1])
DataStore:SetAsync(save, val[2])
end
end)
game.Players.PlayerRemoving:connect(function(plr)
local val = {plr.Rank.Value, plr.Mined.Value}
local save = "plr-"..plr.userId
DataStore:SetAsync(save, val[1])
DataStore:SetAsync(save, val[2])
end)
And I don't know why
-- Any help is appreciated

1 comment
So what I should do is insert the values into a table and JSONEncode it? I don't understand JSONEncoding, I've never played with HTTPService