ProfileService bug

I have installed ProfileService into my new project and everything is working fine, but the issue stems from when I want to create a new value or modify an already existing value in the template. When I try to do this, it doesn’t work and the new value isn’t added until I reset the data store. I’ve made this post many times and haven’t found a working solution. Heres my current code if interested:

function PlayerClass.new(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 Player:IsDescendantOf(Players) == true then
			Profiles[Player] = Profile
			
			PlayerClass:AddLeaderstats(Player)
			PlayerClass:UpdateGiftTimer(Player, Profile)
			
			local Placements = Profile.Data.Placements
			
			for i, v in Profile.Data.HotbarItems do
				local ItemType = TypeClass.GetWeaponType(v)
				RP:WaitForChild("RemoteEvents"):WaitForChild("AddHotbarItem"):FireClient(Player, v, ItemType, nil, Placements)
			end

			UpdateSettings:FireClient(Player, Profile.Data.Settings)
			
			task.spawn(function()
				while task.wait(1) do
					--PlayerClass:HandleXP(Player, Profile, 100)
				end
			end)
			
			
			--PlayerClass:Update(Player, "💎 Diamond", 50000000)

			--PlayerClass:Update(Player)
		else
			Profile:Release()
		end
	else
		Player:Kick()
	end
end

I use :Reconcile() so I don’t understand why this is happening. Any help would be appreciated

Have you provided a valid template to ProfileService.GetProfileStore()? (The function names may be incorrect as I’m writing from memory)

Yes. I have a valid template. Also yes the function name is right, or other wise my entire code wouldn’t work.

May I see the data and the template itself? And the whole code where profile service is utilized?

I have already sent where the profile service was utilized. Heres the config file:

CONFIG.Template = {
	["💎 Diamond"] = 0,
	["⭐️ Level"] = 1,
	HotbarItems = {},
	XP = 0,
	XPToNextLevel = 120,
	TradeCount = 0,
	NukeCountDown = 4,
	NukeCount = 500,
	
	
	GiftSystem = {
		LastReset = os.time(),
		ClaimedGifts = {},
		GiftTimers = {},
		Claimable = 0
	},
	
	Gamepasses = {
		
	},
	
	BlockedPlayers = {
		
	},
	
	Placements = {
		[1] = "Shovels",
		[2] = "Swords",
		[3] = "Guns"
	},
	
	
	Settings = {
		MusicVolume = 0.5,
		SFXVolume = 0.5,
		NightMode = false,
		Flashlight = false,
		Vibrations = false,
		LowGraphics = false,
		RecieveTrades = true,
		
	},
	
	
	Inventory = {
		Chests = {
			["name"] = "Chests",
			
			["Guns"] = {
				["Tier #1"] = 0,
				["Tier #2"] = 0,
				["Tier #3"] = 0,
				["Tier #4"] = 0
			},
			
			["Swords"] = {
				["Tier #1"] = 0,
				["Tier #2"] = 0,
				["Tier #3"] = 0,
				["Tier #4"] = 0
			}
		},
		
		Guns = {

		},
		
		Swords = {

		},
		
		Shovels = {
			
		}
	},
}

I meant the whole PlayerClass script. So we can see if you have done everything correctly

It’s kind of long

local Players = game:GetService("Players")
local RP = game:GetService("ReplicatedStorage")

local RemoteEvents = RP:WaitForChild("RemoteEvents")

local UpdateStatsEvent = RemoteEvents:WaitForChild("UpdateStats")
local UpdateSettings = RemoteEvents:WaitForChild("SettingsChangedRequest")

local ProfileService = require(RP:WaitForChild("ThirdParty"):WaitForChild("ProfileService"))
local TypeClass = require(RP:WaitForChild("Classes"):WaitForChild("Item"):WaitForChild("Types"))

local PlayerClass = {}
PlayerClass.__indext = PlayerClass

local CONFIG = require(script.CONFIG)

local ProfileStore = ProfileService.GetProfileStore(
	"4y3y3y5y53dfgsds",
	CONFIG.Template
)

local Profiles = {}

local ConvertTable = {
	["number"] = "IntValue",
	["string"] = "StringValue",
	["boolean"] = "BoolValue",
}


local Exludes = {"NukeCount", "NukeCountDown", "TradeCount", ""}



local function Minutes(Number)
	return Number * 60
end

local function Hours(Number)
	return Number * 3600
end

local function GetGiftTime(Number)
	return ({
		Minutes(5),
		Minutes(5),
		Minutes(7),
		Minutes(8),
		Minutes(7),
		Minutes(10),
		Minutes(10),
		Minutes(10),
		Minutes(10),
		Minutes(10),
		Minutes(10),
		Minutes(10),

	})[Number]
end

local function ShouldReset(lastReset)
	return os.time() - lastReset >= 86400
end

function PlayerClass.new(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 Player:IsDescendantOf(Players) == true then
			Profiles[Player] = Profile
			
			PlayerClass:AddLeaderstats(Player)
			PlayerClass:UpdateGiftTimer(Player, Profile)
			
			local Placements = Profile.Data.Placements
			
			for i, v in Profile.Data.HotbarItems do
				local ItemType = TypeClass.GetWeaponType(v)
				RP:WaitForChild("RemoteEvents"):WaitForChild("AddHotbarItem"):FireClient(Player, v, ItemType, nil, Placements)
			end

			UpdateSettings:FireClient(Player, Profile.Data.Settings)
			
			task.spawn(function()
				while task.wait(1) do
					--PlayerClass:HandleXP(Player, Profile, 100)
				end
			end)
			
			
			--PlayerClass:Update(Player, "💎 Diamond", 50000000)

			--PlayerClass:Update(Player)
		else
			Profile:Release()
		end
	else
		Player:Kick()
	end
end

function PlayerClass:AddLeaderstats(Player)
	local Profile = Profiles[Player]
	
	if not Profile then -- used for laggy players or bad internet
		repeat
			Profile = Profiles[Player]
			task.wait(0.3)
		until Profile
	end

	local Ld = Instance.new("Folder")
	Ld.Name = "leaderstats"
	Ld.Parent = Player
	
	local t = Instance.new("Folder")
	t.Name = "Other"
	t.Parent = Player
	
	if not Player.Character then
		repeat
			task.wait()
		until Player.Character
	end

	for i, v in Profile.Data do
		local ValueType = typeof(v)
		
		if ValueType == "table" or table.find(Exludes, i) then continue end

		local ValueT = Instance.new(ConvertTable[ValueType])

		if ValueT then
			ValueT.Name = i
			ValueT.Value = v
			ValueT.Parent = if i == "XP" or i == "XPToNextLevel" then t else Ld
			
			UpdateStatsEvent:FireClient(Player, ValueT.Name, ValueT.Value)
		end
	end
end

function PlayerClass:HandleXP(Player, Profile, Amount: number)
	local XP = Profile.Data.XP
	local Level = Profile.Data["⭐️ Level"]
	local XPToNextLevel = Profile.Data.XPToNextLevel
	
	XP+=Amount
	
	while XP >= XPToNextLevel do -- 120 >= 120
		XP -= XPToNextLevel -- 120 - 120 = 0
		Level += 1
		XPToNextLevel = math.floor(20 + Level * 50)
		task.wait(0.1)
	end

	PlayerClass:Update(Player, "XP", XP)
	PlayerClass:Update(Player, "XPToNextLevel", XPToNextLevel)
	
	if Profile.Data["⭐️ Level"] == Level then return end -- make sure to not update level if it didn't change
	
	PlayerClass:Update(Player, "⭐️ Level", Level)
end

function PlayerClass:UpdateGiftTimer(Player: Player, Profile)
	task.spawn(function()
		repeat
			task.wait()
		until Player.Character -- prevents loop from running until the character loads
		
		while true do
			for x = 1, 12 do
				local CurrentTime = Profile.Data.GiftSystem.GiftTimers[x] or GetGiftTime(x)
				Profile.Data.GiftSystem.GiftTimers[x] = CurrentTime

				RemoteEvents.GiftUpdate:FireClient(Player, x, {TimeLeft = Profile.Data.GiftSystem.GiftTimers[x], Claimed = Profile.Data.GiftSystem.ClaimedGifts[x]})

				Profile.Data.GiftSystem.GiftTimers[x] -= 1

				Profile.Data.GiftSystem.GiftTimers[x] = math.clamp(Profile.Data.GiftSystem.GiftTimers[x], 0, math.huge)
			end

			task.wait(1)
		end
	end)
end

function PlayerClass:Update(Player: Player, Key: string, Value: number)
	local Profile = Profiles[Player]
	if not Profile then return end

	Profile.Data[Key] = Value
	
	local ld = Player:WaitForChild("leaderstats")
	local Other = Player:WaitForChild("Other")
	
	UpdateStatsEvent:FireClient(Player, Key, Value)
	
	if ld:FindFirstChild(Key) then
		ld[Key].Value = Profile.Data[Key]
		
	elseif Other:FindFirstChild(Key) then
		Other[Key].Value = Profile.Data[Key]
	else
		return
	end
end

function PlayerClass:GetProfileData(Player)
	local Profile = Profiles[Player]
	
	repeat task.wait()
		Profile = Profiles[Player]
	until Profile
	
	return Profile
end

function PlayerClass:ReleaseProfile(Player)
	if Profiles[Player] then
		local Profile = Profiles[Player]
		Profile:Release()
	end
end


return PlayerClass