I can not figure out why my code is not working:
local DefaultData = {
["CurrentStats"] = {
["CityLevel"] = 0,
["CityPopulation"] = 0,
["CityVisits"] = 0,
["CoinsPerSecond"] = 0,
["Coins"] = 0,
["Cash"] = 0,
["AchievementsCompleted"] = 0,
["HasAirport"] = false,
["HasForeverDoubleEarnings"] = false,
},
["HighestStats"] = {
["HighestCityLevel"] = 0,
["HighestCityPopulation"] = 0,
["HighestCoins"] = 0,
["HighestCash"] = 0,
["HighestAchievementsCompleted"] = 0
}
}
local PlayerDataTable
game:GetService("Players").PlayerAdded:Connect(function(Player)
print(Player.Name)
local playerKey = tostring("key-"..Player.UserId.."-devtechgames")
local playerData
local success,err = pcall(function()
local playerData = PlayerStats:GetAsync(playerKey) or DefaultData
end)
if success then
if playerData then
PlayerDataTable = playerData
print("Player has data")
else
print("Player has no data")
print(playerData)
end
end
end)
game:GetService("Players").PlayerRemoving:Connect(function(Player)
local playerKey = tostring("key-"..Player.UserId.."-devtechgames")
local success,err = pcall(function()
PlayerStats:UpdateAsync(playerKey,function(oldData)
local newData = oldData or DefaultData
print("Saved data")
return newData
end)
end)
end)
This is the output:
Every time i join it is saying the data is non existent even though it should be there.
EDIT:
I do have API services enabled