I had this code for awhile now, but on line 16 I cant convert to json? I try using other things inside the table, just making sure it wasnt coins, but it's on all. how do I fix? what am I doing wrong, thanks!
local DataStore = game:GetService("DataStoreService"):GetDataStore("TestV2")
local HttpService = game:GetService("HttpService");
local PlayerData = {}
local StarterPlayerData = { ['Coins'] = 12312313, ['Diamonds'] = 0, ['Codes'] = 0, ['Kills'] = 0}
game.Players.PlayerAdded:Connect(function(plr)
local key = "user_"..plr.UserId
if DataStore:GetAsync(key) == nil then
PlayerData[plr] = StarterPlayerData
else
PlayerData[plr] = HttpService:JSONDecode(DataStore:GetAsync(key));
end
print(HttpService:JSONEncode(PlayerData[plr]['Coins']))
end)
game.Players.PlayerRemoving:Connect(function(plr)
local key = "user_"..plr.UserId
if PlayerData[plr] == nil then
DataStore:SetAsync(key, HttpService:JSONEncode(PlayerData[plr]))
end
end)

1 comment
This works thanks!