Hey! I’m getting this error in the title.
Script:
players.PlayerRemoving:Connect(function(plr)
--Save his data
local success, errormessage = pcall(function()
local realStats = plr:WaitForChild("realStats")
local tableToSave = {realStats:WaitForChild("Coins").Value, realStats:WaitForChild("Gems").Value, realStats:WaitForChild("Gifts").Value}
StatsDataStore:UpdateAsync(plr.UserId, function()
return tableToSave
end)
end)
if errormessage then --Try again
print(errormessage)
local realStats = plr:WaitForChild("realStats")
local tableToSave = {realStats:WaitForChild("Coins").Value, realStats:WaitForChild("Gems").Value, realStats:WaitForChild("Gifts").Value}
StatsDataStore:UpdateAsync(plr.UserId, function()
return tableToSave
end)
end
end)
game:BindToClose(function()
for i,v in next, players:GetPlayers() do
local success, errormessage = pcall(function()
local realStats = v:WaitForChild("realStats")
local tableToSave = {realStats:WaitForChild("Coins").Value, realStats:WaitForChild("Gems").Value, realStats:WaitForChild("Gifts").Value}
StatsDataStore:UpdateAsync(v.UserId, function()
return tableToSave
end)
end)
if errormessage then
local realStats = v:WaitForChild("realStats")
local tableToSave = {realStats:WaitForChild("Coins").Value, realStats:WaitForChild("Gems").Value, realStats:WaitForChild("Gifts").Value}
StatsDataStore:UpdateAsync(v.UserId, function()
return tableToSave
end)
end
end
end)
Can you see anything wrong with it? Thanks.