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
Are you saving tables? If you are, you should be using JSONEncode and JSONDecode. These are functions of HttpService, and they allow you to convert tables to strings, and JSON strings to tables.
First, make sure that HttpService is enabled. Then...
http = game:GetService("HttpService") t = { Level = 1, Gold = 100 } jt = http:JSONEncode(t) print(jt)
And basically, you can use this to save JSON strings rather than tables.