I use ProfileService for my game, World War Tycoon. 99% of the time, it works extremely well, but about 1% of the time, there is an issue where a player joins the game, their stats do not load whatsoever, and this error is thrown:
After looking through the ProfileService thread, there were a few people who had a similar issue, like below
In my usage of ProfileService, I have ProfileService initialized + first called to get a player’s stat saves. One of the stats then refers to a ModuleScript, to see if the player is eligible for daily rewards based on their rank in the game, based on the last time they played, which is also saved into ProfileService.
Leaderboard code snippet:
local ProfileService = require(game.ServerScriptService.profileService.PlayerDataHandler)
local getCash = require(game:GetService("ServerScriptService").stats.getCash)
game.Players.PlayerAdded:Connect(function(Player)
ProfileService:playerAdded(Player)
local stats = createStat("IntValue",Player,"leaderstats",0)
local cash = createStat("IntValue",stats,"Cash",getCash.get(Player,true),Player)
---- rest of code here
end)
ModuleScript Code Snippet:
local ProfileService = require(game.ServerScriptService.profileService.PlayerDataHandler)
function getCash.get(plr:Player,init,gamepass)
local lastPlay = ProfileService:Get(plr,"lastPlayed")
if os.time() - lastPlay >= dailyRewardsTimer then
print(tostring(plr).."'s played exactly a day ago!")
end
end
So, technically, ProfileService is accessed by two different scripts, one a regular server script, and one a ModuleScript that is called by that same server script a little later. It seems like this has a very minor chance of error, but I want there to be next to 0% error, especially as the game scales up.
How would I fix this issue?