I keep getting sprayed with errors regarding ProfileService not returning my data. This only happens every so often, so the code DOES work, but every so often it just decides to not load data.
function DataService:Get(player)
local Profile = self.Profiles[player]
if not Profile then
self.DataLoaded:Wait()
Profile = self.Profiles[player]
end
return Profile.Data -- attempt to index nil with 'Data'
end
From what I can tell here, Profile should NEVER be nil. So I am unsure how or why it’s getting nil. As mentioned before, this does work 9/10. I am passing a valid player in every case. So I don’t know, unless ProfileService.DataLoaded is firing before the players data has actually loaded, but it shouldn’t as it’s at the bottom of my load function
function DataService:Load(player)
local ProfileStore = ProfileService.GetProfileStore(
KEY,
Template
)
local Profile = ProfileStore:LoadProfileAsync("Player_" .. player.UserId)
if Profile ~= nil then
Profile:AddUserId(player.UserId) -- GDPR compliance
Profile:Reconcile() -- Fill in missing variables from ProfileTemplate (optional)
-- The profile could've been loaded on another Roblox server
Profile:ListenToRelease(function()
self.Profiles[player] = nil
player:Kick()
end)
if player:IsDescendantOf(Players) then -- Profile has been successfully loaded
self.Profiles[player] = Profile
--DoSomethingWithALoadedProfile(player, profile)
else -- Player left before the profile loaded
Profile:Release()
end
else -- Profile couldn't be loaded
player:Kick()
end
self.DataLoaded:Fire()
print("✅ | Data has loaded for " .. player.Name .. "!")
end