Hello! I experienced this Error today. I wrote this script earlier and it worked great! Out of no where, it stopped working and would no longer save data. I know It will not Save when the player object is removed due to the fact the the Data Table is not getting encoded due to some unknown error while encoding the Data Table. My output is fully clear and I tried reverting script versions, made sure the API is Enabled and attempted troubleshooting. I pasted my code below. Keep in mind that it was working just fine earlier when I wrote it . Strange ![]()
Blockquote
local DataStoreService = game:GetService(“DataStoreService”)
local DataStore = DataStoreService:GetDataStore(“DataStore523”)
local Players = game:GetService(“Players”)
local HttpService = game:GetService(“HttpService”)
local Table = {}
Players.PlayerAdded:Connect(function(Player)
local Key = “Key-”..Player.UserId
local Folder = Instance.new(“Folder”)
Folder.Name = “leaderstats”
Folder.Parent = Player
local Value1 = Instance.new("NumberValue")
Value1.Name = "Money"
Value1.Parent = Folder
local Value2 = Instance.new("IntValue")
Value2.Name = "Cash"
Value2.Parent = Folder
local Data = DataStore:GetAsync(Key)
if Data then
Table = Data or {}
for i,v in pairs(Table) do
Value1.Value = v[1]
Value2.Value = v[2]
end
else
Value1.Value = 500
Value2.Value = 0
end
end)
Players.PlayerRemoving:Connect(function(Player)
local Key = “Key-”..Player.UserId
local Folder = Player.leaderstats
table.clear(Table)
table.insert(Table, {Folder.Money.Value, Folder.Cash.Value})
DataStore:SetAsync(Key, Table)
print(HttpService:JSONEncode(Table))
end)