Issue with Season Pass not saving on the proper folder

I am trying to fix the Season Pass in my game until my back-end developer took a long hiatus and left me to fix this problem, so basically, the problem is the values “HasClaimedFreeReward” to “XP” is not being saved on the “6.3” folder which is supposed to be where it’s at.

image

Here’s the main Player Data Handler:

local PlayerHandler = {}

--SERVICES--
local DataStoreService = game:GetService("DataStoreService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local PhysicsService = game:GetService("PhysicsService")
local MarketplaceService = game:GetService("MarketplaceService")
local BadgeService = game:GetService("BadgeService")
local ServerStorage = game.ServerStorage
local Players = game.Players

--SUBMODULES--
PlayerHandler.Data = require(script:FindFirstChild("Data"))
PlayerHandler.Migration = require(script:FindFirstChild("Migration"))
PlayerHandler.PlayerStatsTemplate = require(ServerStorage.Assets.GameData:WaitForChild("PlayerStatsTemplate"))

--PRIVATE VARIABLES--
local Season = ReplicatedStorage.Season.Value
local SeasonPassRewards = ReplicatedStorage.SeasonPassRewards:GetChildren()

local LegacyCheckStore = DataStoreService:GetDataStore("CurrencyGAMING-00000500")
local MigratedPlayersStore = DataStoreService:GetDataStore("MigratedPlayers")

--PRIVATE FUNCTIONS--
local function LoadDataToValue(Player, v, Category, Index)
	local Profile = PlayerHandler.Data:GetProfileFromPlayer(Player)

	if Profile.Data[Category] ~= nil then
		if Index then
			if Profile.Data[Category][Index] ~= nil then
				v.Value = Profile.Data[Category][Index][v.Name]
			else
				warn("Unable to find index " .. Index .. "In category " .. Category)
			end
		else
			if Profile.Data[Category][v.Name] ~= nil then
				v.Value = Profile.Data[Category][v.Name]
			end
		end
	end
	
	return
end

local function SyncDataWithValue(Player, Value, Category)
	local Profile = PlayerHandler.Data:GetProfileFromPlayer(Player)
	local LastUpdated = 0
	local Yielding = false

	Value:GetPropertyChangedSignal("Value"):Connect(function()
		if time() - LastUpdated < 5 then
			if not Yielding then
				Yielding = true
				task.wait(5)
				Yielding = false
			else
				return
			end
		end

		LastUpdated = time()

		if not Category then
			Profile.Data[Value.Name] = Value.Value
		else
			if not Profile.Data[Category] then
				Profile.Data[Category] = {}
			end

			Profile.Data[Category][Value.Name] = Value.Value
		end
	end)
end

local function GeneratePlayerValues(Player, Template, Parent, Category)
	local Parent = Parent or Player -- dumb recursive hack

	for Index, Value in pairs(Template) do
		local ClassName = PlayerHandler.Data.Serialization.TypeClassNames[typeof(Value)]

		if ClassName then			
			if ClassName == "Folder" then -- HARDCODED NONSENSE BUT I GOTTA DO THIS
				if Category ~= "SeasonPass" then
					local Folder = PlayerHandler.Data.Serialization:CreateFolder(Parent, tostring(Index))
					GeneratePlayerValues(Player, Value, Folder, Index)
				end
			else
				local Value = PlayerHandler.Data.Serialization:CreateValue(Parent, ClassName, Index, Value)

				if Category ~= "SeasonPass" then
					LoadDataToValue(Player, Value, Category)
					SyncDataWithValue(Player, Value, Category)
				else
					LoadDataToValue(Player, Value, Category, Season)
					SyncDataWithValue(Player, Value, Category)
				end
			end
		end
	end	
end

local function LoadSeasonPass(Player)
	local Profile = PlayerHandler.Data:GetProfileFromPlayer(Player)
	
	GeneratePlayerValues(Player, PlayerHandler.PlayerStatsTemplate.SeasonPass[0], Player.SeasonPass, "SeasonPass")
	
	for i = 1, #SeasonPassRewards do
		local Tier = Instance.new("BoolValue", Player.SeasonPass)
		Tier.Name = "Tier " .. i

		LoadDataToValue(Player, Tier, "SeasonPass", Season)
		
		Tier:GetPropertyChangedSignal("Value"):Connect(function()
			Profile.Data["SeasonPass"][Season][Tier.Name] = Tier.Value
		end)
		
		if i % 10 == 0 then
			task.wait(1.5)
		end
	end
end

local function GenerateValuesFromNames(ListInstance, Player, Parent, ValueType, DefaultValue, Category, NamePattern) -- parameter hell, should have used tables
	for i, Object in pairs(ListInstance:GetChildren()) do
		local Name = NamePattern and string.format(NamePattern, Object.Name) or Object.Name
		local Value = PlayerHandler.Data.Serialization:CreateValue(Parent, ValueType, Name, DefaultValue)

		LoadDataToValue(Player, Value, Category)
		SyncDataWithValue(Player, Value, Category)
	end
end

local function GenerateShopItems(ListInstance, Player, Parent, ValueType)
	for i, Object in pairs(ListInstance:GetChildren()) do
		local Name = ListInstance:GetAttribute("ItemType") == "Background" and Object.Name 
			or string.format("%s %s", ListInstance:GetAttribute("ItemType"), Object.Name)

		local Value = PlayerHandler.Data.Serialization:CreateValue(Parent, ValueType, Name, false)

		LoadDataToValue(Player, Value, "ShopItems")
		SyncDataWithValue(Player, Value, "ShopItems")
	end
end

local function LoadPlayerData(Player)	
	local Profile = PlayerHandler.Data:CreateProfile(Player)
	
	if not Profile then
		return
	end
	
	if not Profile.Data.SeasonPass then
		Profile.Data.SeasonPass = {}
	end

	if not Profile.Data.SeasonPass[Season] then -- right here
		Profile.Data.SeasonPass[Season] = PlayerHandler.PlayerStatsTemplate.SeasonPass[0]
	end

	if LegacyCheckStore:GetAsync(Player.UserId) then
		if not MigratedPlayersStore:GetAsync(Player.UserId) then
			print("Migrating " .. Player.Name)
			PlayerHandler.Migration:Migrate(Player.UserId, Profile)
		end
	end

	GeneratePlayerValues(Player, PlayerHandler.PlayerStatsTemplate)

	GenerateValuesFromNames(ReplicatedStorage.Microgames, Player, Player.Microgames, "IntValue", 0, "Microgames")
	GenerateValuesFromNames(ReplicatedStorage.Boss, Player, Player.Microgames, "IntValue", 0, "Microgames")

	GenerateShopItems(ReplicatedStorage.ShopBG, Player, Player.ShopItems, "BoolValue")
	GenerateShopItems(ReplicatedStorage.ShopVoices, Player, Player.ShopItems, "BoolValue")
	GenerateShopItems(ReplicatedStorage.ShopJingles, Player, Player.ShopItems, "BoolValue")
	GenerateShopItems(ReplicatedStorage.ShopFrames, Player, Player.ShopItems, "BoolValue")
	GenerateShopItems(ReplicatedStorage.ShopHeartIcons, Player, Player.ShopItems, "BoolValue")
	
	LoadSeasonPass(Player)
	--GenerateValuesFromNames(ReplicatedStorage.SeasonPassRewards, Player, Player.SeasonPass, "BoolValue", false, "SeasonPass", "Tier %s") -- lol
	--GeneratePlayerValues(Player, PlayerHandler.PlayerStatsTemplate.SeasonPass[0], Player.SeasonPass, "SeasonPass")

	-- go through all tiers above the current one and unclaim

	--if #ReplicatedStorage.SeasonPassRewards:GetChildren() - Player.SeasonPass.Tier.Value > 0 then
	--	for i = Player.SeasonPass.Tier.Value, #ReplicatedStorage.SeasonPassRewards:GetChildren() do
	--		local Tier = Player.SeasonPass:FindFirstChild(string.format("Tier %d", i))

	--		if Tier and i > 1 then
	--			--print("negate " .. Tier.Name)
	--			Tier.Value = false
	--		end
	--	end		
	--end
	
	return Profile
end

local function CharacterAdded(Player, Character)
	repeat wait() until Player and Player.Character and Player.Character:FindFirstChild("Humanoid")
	local Humanoid = Character:WaitForChild("Humanoid")
	local LastHealth = Humanoid.Health

	Humanoid.Died:Connect(function()
		task.delay(Players.RespawnTime, function()
			Character:Destroy()

			if Player.Parent == Players then
				Player:LoadCharacter()
			end
		end)
	end)

	local Forcefield = Instance.new("ForceField")
	Forcefield.Parent = Character

	Humanoid.BreakJointsOnDeath = false
end

local function PlayerAdded(Player)
	local Profile = LoadPlayerData(Player)
	
	if Player.Parent == Players and Profile then
		Player:LoadCharacter()

		Player.CharacterAdded:Connect(function(Character)
			CharacterAdded(Player, Character)
		end)

		repeat wait() until Player.Character
		CharacterAdded(Player, Player.Character)
	end
end

local function Initialize()
	PhysicsService:CreateCollisionGroup("Players")
	PhysicsService:CollisionGroupSetCollidable("Players", "Players", false)

	for i, Player in pairs(Players:GetPlayers()) do
		local Success, Error = pcall(function()
			coroutine.wrap(PlayerAdded)(Player)
		end)

		if not Success then
			warn(Error)
		end
	end
end

--INIT--
Initialize()

--EVENT SUBSCRIPTION--
Players.PlayerAdded:Connect(PlayerAdded)
Players.PlayerRemoving:Connect(function(Player)
	local Profile = shared.PlayerProfiles[Player.Name]

	if Profile ~= nil then
		Profile:Release()
	end
end)

Is there a fix for this? Let me know if you need anything else to solve this issue.