Yes, I know this isn't a request site, but I'm not requesting, I'm asking for assistance, nothing on the Wiki helps and I can't find a tutorial. The reason I need to JSONEncode is because whenever I update my game it sets all the player's values to the default. This is my current script:
DataStore = game:GetService("DataStoreService"):GetDataStore("Values")
game.Players.PlayerAdded:connect(function(plr)
local stat = Instance.new("IntValue", plr)
stat.Name = "leaderstats"
local cred = Instance.new("IntValue", stat)
cred.Value = 0
cred.Name = "Credits"
local save = "plr-"..plr.userId
local savedVals = DataStore:GetAsync(save)
if savedVals then
cred.Value = savedVals[1]
else
local val = {cred.Value}
DataStore:SetAsync(save, val[1])
end
end)
game.Players.PlayerRemoving:connect(function(plr)
local val = {plr.leaderstats.Credits.Value}
local save = "plr-"..plr.userId
DataStore:SetAsync(save, val[1])
end)
