Profile Service Issue!

I dont know how or why but i started getting this error everytime i tried press play in studio.

1 Like

How are you handling the profiles when the player joins and leaves? Are you sure that the profile actually loads?

1 Like
local function onPlayerAdded(Player)
	local profile = ProfileStore:LoadProfileAsync(
		"Player_"..Player.UserId,
		"ForceLoad"
	)

	if profile then
		profile:AddUserId(Player.UserId)
		profile:Reconcile()
		profile:ListenToRelease(function()
			Profiles[Player] = nil
			Player:Kick()
		end)

		if Player:IsDescendantOf(Players) then
			Profiles[Player] = profile
			replicaData(Player)
		else
			profile:Release()
		end
	else
		Player:Kick()
	end
end

local function onPlayerRemoving(Player)
	local profile = Profiles[Player]
	if profile then
		profile:Release()
	end
end

for _, Player in ipairs(Players:GetPlayers()) do
	task.spawn(onPlayerAdded, Player)
end

Players.PlayerAdded:Connect(onPlayerAdded)

Players.PlayerRemoving:Connect(onPlayerRemoving)

local DataCache = {}

function DataCache.getProfileTemplate()
	return ProfileTemplate
end

function DataCache.GetDataFrom(Player)
	local profile = Profiles[Player]

	return profile.Data
end

function DataCache.GetDataFromUserId(UserId)
	local profile = ProfileStore:ViewProfileAsync("Player_".. UserId)

	return profile.Data
end

function DataCache.Wipe(UserId)
	ProfileStore:WipeProfileAsync("Player_".. UserId)
end

return DataCache