Help with profile service

Hi. I am currently working on a stats system for my game and I cannot use the get method. Specifically, the script thinks profile[player] is nil. I even checked with a database editor plugin that the key I am using when calling the get method is valid:
image

Full Code:



local Players = game:GetService("Players")
local ProfileService = require(game.ServerScriptService.ProfileService)

local template = 	{
	forms = {},
	style = "basic",
	hunger = 100,
	cash = 500,
	strength = 0,
	durability = 0,
	clan = "UNDEFINED",
	name = "UNDEFINED",
	clanRerolls = 5
	
}

local ProfileStore = ProfileService.GetProfileStore(
	"Player",
	template
)

local Profiles = {}


local function onPlayerAdded(player)
	local profile = ProfileStore:LoadProfileAsync(
		"Player_" .. player.UserId,
		"ForceLoad"
	)
	
	if profile then
		
		
		profile:ListenToRelease(function()
			Profiles[player] = nil
			player:Kick("Session Lock Released.")
		end)
		
		if player:IsDescendantOf(Players) then --// Check if player is still within the game
			Profiles[player] = profile
			
                        --// If profile is missing a value from template or has anything that template does not have, fix it
			for i,v in pairs(profile.Data) do
				if template[i] == nil then
					profile.Data[i] = nil
				end
			end
			
			for i,v in pairs(template) do
				if profile.Data[i] == nil then
					profile.Data[i] = v
				end
			end
			
			warn("--PROFILE LOADED--")
			warn(profile)
			
			if not script.Loaded.Value then
				script.Loaded.Value = true
			end
			
		else
			profile:Release() --// If not, then release session lock
		end
	else
		player:Kick("There was an error loading player data.")
	end
end

local function onPlayerRemoving(player) --// when the player leaves, release the session lock on their profile
	local profile = Profiles[player]
	if profile then
		profile:Release()
	end
end

Players.PlayerAdded:Connect(onPlayerAdded)
Players.PlayerRemoving:Connect(onPlayerRemoving)


local DataManager = {}

function DataManager:Get(player)
	warn(Profiles)
	local profile = Profiles

	
	if profile then
		warn("profile exists")
		return profile
	end
	
end

return DataManager
1 Like
function DataManager:Get(player)
	warn(Profiles)
	local profile = Profiles[player]

	
	if profile then
		warn("profile exists")
		return profile
	end
	
end

I am a bit confused on what this means?

You were returning the data of all players rather than one specific player’s data(unless that’s what you wanted)