HGreetings,
I am writing in regards to an error encountered while attempting to retrieve player data using ProfileService. Specifically, when executing the script, the following error is generated:
ServerScriptService.PlayerData.PlayerDataHandler:52: Profile does not exist 2969205434
The error only occurs when executing the following code:
if PlayerDataHandler:Get(player, "Slots") == 1 then
print("[DEBUG], %s", player.Name)
end
For your reference, the code is part of the PlayerDataHandler module, which is responsible for handling player data. The module utilizes the ProfileService library to manage player profiles. Here is a breakdown of the relevant code:
This is the PlayerDataHandler:
local PlayerDataHandler = {}
local ProfileService = require(game:GetService("ServerScriptService").Libs:FindFirstChild("ProfileService"))
local Players = game:GetService("Players")
local ProfileStore = ProfileService.GetProfileStore("PlayerProfile", {
Name = "Dontalius",
Race = "Human",
Slots = 1
})
local Profiles = {}
playerAdded = function(player)
local profile = ProfileStore:LoadProfileAsync("Player_"..player.UserId)
if profile then
profile:AddUserId(player.UserId)
profile:Reconcile()
profile:ListenToRelease(function()
Profiles[player] = nil
player:Kick()
end)
if not player:IsDescendantOf(Players) then
profile:Release()
else
Profiles[player] = profile
end
else
player:Kick()
end
end
PlayerDataHandler.Init = function()
for _, player in game.Players:GetPlayers() do
task.spawn(playerAdded, player)
end
game.Players.PlayerAdded:Connect(playerAdded)
game.Players.PlayerRemoving:Connect(function(player)
if Profiles[player] then
Profiles[player]:Release()
end
end)
end
getProfile = function(player)
assert(Profiles[player], string.format("Profile does not exist %s", player.UserId))
return Profiles[player]
end
-- Getter/Setter methods
function PlayerDataHandler:Get(player, key)
local profile = getProfile(player)
assert(profile.Data[key], string.format("Data does not exist for key: %s", key))
return profile.Data[key]
end
function PlayerDataHandler:Set(player, key, value)
local profile = getProfile(player)
assert(profile.Data[key], string.format("Data does not exist for key: %s", key))
assert(type(profile.Data[key]) == type(value))
profile.Data[key] = value
end
function PlayerDataHandler:Update(player, key, callback)
local profile = getProfile(player)
local oldData = self:Get(player, key)
local newData = callback(oldData)
self:Set(player, key, newData)
end
return PlayerDataHandler