Profile service not working properly... can someone help pls?

for some reason my profile service script is not working. can u guys please help me???

this is the leaderstats script

game.Players.PlayerAdded:Connect(function(player)
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local Level = Instance.new("NumberValue")
	Level.Name = "Lvl"
	Level.Parent = player
	Level.Value = 1

	local ExpMultiplier = Instance.new("NumberValue")
	ExpMultiplier.Name = "ExpMultiplier"
	ExpMultiplier.Parent = player
	ExpMultiplier.Value = 1

	local Exp = Instance.new("NumberValue")
	Exp.Name = "Exp"
	Exp.Parent = player
	Exp.Value = 0

	local Wins = Instance.new("NumberValue")
	Wins.Name = "Victories"
	Wins.Parent = leaderstats
	Wins.Value = 0

	local RequiredExp = Instance.new("NumberValue")
	RequiredExp.Name = "RequiredExpPlr"
	RequiredExp.Parent = player
	RequiredExp.Value = 300

	local Money = Instance.new("NumberValue")
	Money.Name = "Money"
	Money.Parent = player
	Money.Value = 0

	local Tokens = Instance.new("NumberValue")
	Tokens.Name = "Tokens"
	Tokens.Parent = player
	Tokens.Value = 0

	local MaxHealth = Instance.new("NumberValue")
	MaxHealth.Name = "MaxHealth"
	MaxHealth.Parent = player
	MaxHealth.Value = 100

	local Damage = Instance.new("NumberValue")
	Damage.Name = "Damage"
	Damage.Parent = player
	Damage.Value = 0

	local WalkSpeed = Instance.new("NumberValue")
	WalkSpeed.Name = "WalkSpeed"
	WalkSpeed.Parent = player
	WalkSpeed.Value = 16

	local HealthCost = Instance.new("NumberValue")
	HealthCost.Name = "HealthCost"
	HealthCost.Parent = player
	HealthCost.Value = 1

	local DamageCost = Instance.new("NumberValue")
	DamageCost.Name = "DamageCost"
	DamageCost.Parent = player
	DamageCost.Value = 1

	local SpeedCost = Instance.new("NumberValue")
	SpeedCost.Name = "SpeedCost"
	SpeedCost.Parent = player
	SpeedCost.Value = 1

	local CelestialPotion = Instance.new("NumberValue")
	CelestialPotion.Name = "CelestialPotion"
	CelestialPotion.Parent = player
	CelestialPotion.Value = 0

	local PowerPotion = Instance.new("NumberValue")
	PowerPotion.Name = "PowerPotion"
	PowerPotion.Parent = player
	PowerPotion.Value = 0

	local ShiningStaff = Instance.new("NumberValue")
	ShiningStaff.Name = "ShiningStaff"
	ShiningStaff.Parent = player
	ShiningStaff.Value = 0

	local Detector = Instance.new("NumberValue")
	Detector.Name = "Detector"
	Detector.Parent = player
	Detector.Value = 0

	local ConjureStaff = Instance.new("NumberValue")
	ConjureStaff.Name = "ConjureStaff"
	ConjureStaff.Parent = player
	ConjureStaff.Value = 0

	local FusionCoil = Instance.new("NumberValue")
	FusionCoil.Name = "FusionCoil"
	FusionCoil.Parent = player
	FusionCoil.Value = 0

	-- Level up system
	Exp.Changed:Connect(function()
		while Exp.Value >= RequiredExp.Value do
			Exp.Value -= RequiredExp.Value
			Level.Value += 1
			Tokens.Value += 1

			if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
				local sound = game.Workspace.Sounds.LevelUpSound:Clone()
				sound.Parent = player.Character.HumanoidRootPart
				sound:Play()
				game.Debris:AddItem(sound, 4)
			end

			RequiredExp.Value = Level.Value * 300
		end
	end)
end)

and this is the actual profile service script here

local ProfileStore = require(script.ProfileStore)

local Players = game:GetService("Players")

local Profiles: {[player]: typeof(PlayerStore:StartSessionAsync())} = {}

local function PlayerAdded(player)
	
	-- The PROFILE_TEMPLATE table is what new profile "Profile.Data" will default to:
	local PROFILE_TEMPLATE = {
		Lvl = player.Lvl.Value,
		Exp = player.Exp.Value,
		RequiredExp = player.RequiredExpPlr.Value,
		Victories = player.leaderstats.Victories.Value,
		Money = player.Money.Value,
		MaxHealth = player.MaxHealth.Value,
		Damage = player.Damage.Value,
		WalkSpeed = player.WalkSpeed.Value,
		Tokens = player.Tokens.Value,
		HealthCost = player.HealthCost.Value,
		DamageCost = player.DamageCost.Value,
		SpeedCost = player.SpeedCost.Value,
		ExpMultiplier = player.ExpMultiplier.Value,
		CelestialPotion = player.CelestialPotion.Value,
		PowerPotion = player.PowerPotion.Value,
		ShiningStaff = player.ShiningStaff.Value,
		Detector = player.Detector.Value,
		ConjureStaff = player.ConjureStaff.Value,
		FusionCoil = player.FusionCoil.Value,
	}

	local PlayerStore = ProfileStore.New("PlayerStore", PROFILE_TEMPLATE)

	-- Start a profile session for this player's data:

	local profile = PlayerStore:StartSessionAsync(`{player.UserId}`, {
		Cancel = function()
			return player.Parent ~= Players
		end,
	})

	-- Handling new profile session or failure to start it:

	if profile ~= nil then

		profile:AddUserId(player.UserId) -- GDPR compliance
		profile:Reconcile() -- Fill in missing variables from PROFILE_TEMPLATE (optional)

		profile.OnSessionEnd:Connect(function()
			Profiles[player] = nil
			player:Kick(`Profile session end - Please rejoin`)
		end)

		if player.Parent == Players then
			Profiles[player] = profile
			print(`Profile loaded for {player.DisplayName}!`)
			-- EXAMPLE: Grant the player 100 coins for joining:
			-- You should set "Cash" in PROFILE_TEMPLATE and use "Profile:Reconcile()",
			-- otherwise you'll have to check whether "Data.Cash" is not nil
		else
			-- The player has left before the profile session started
			profile:EndSession()
		end

	else
		-- This condition should only happen when the Roblox server is shutting down
		player:Kick(`Profile load fail - Please rejoin`)
	end

end

-- In case Players have joined the server earlier than this script ran:
for _, player in Players:GetPlayers() do
	task.spawn(PlayerAdded, player)
end

Players.PlayerAdded:Connect(PlayerAdded)

Players.PlayerRemoving:Connect(function(player)
	local profile = Profiles[player]
	if profile ~= nil then
		profile:EndSession()
	end
end)

Can you explain what exactly is not working? What are you expecting to happen and what are you actually seeing happen?

its ok i managed to fix it by watching a vid but ty

1 Like