local function r(r)return math.floor(300+(r/100)^4*300)end local function H(H)local o=PLAYER_DATA:FindFirstChild(H.Name)if o then local S=o.Ranking local d=o.BattlePass if S.CurrentSeason.Value==CURRENT_SEASON then local o=S.Level.Value repeat local o=r(S.Level.Value+1)if S.LevelXP.Value>=o then S.LevelXP.Value=S.LevelXP.Value-o S.Level.Value=S.Level.Value+1 script.Parent.BattlePassScript.LevelUp:Fire(H,S.Level.Value)end until S.LevelXP.Value<o if S.Level.Value>o then REMOTES.LevelUp:FireClient(H)end else S.Rank.Value=S.Rank.Value+S.Level.Value S.Level.Value=0 S.LevelXP.Value=0 d.XPBoost.Value=0 S.CurrentSeason.Value=CURRENT_SEASON end end end local function o(r)local H=PLAYER_DATA:FindFirstChild(r.Name)if H then if H.Ranking.Level.Value<100 then H.Ranking.Level.Value=H.Ranking.Level.Value+1 script.Parent.BattlePassScript.LevelUp:Fire(r,H.Ranking.Level.Value)REMOTES.LevelUp:FireClient(r)return true end end return false end
-- functions

local function XPForLevel(level)
	return math.floor(300 + (level / 100) ^ 4 * 300)
end

local function UpdateLevels(player)
	local playerData = PLAYER_DATA:FindFirstChild(player.Name)
	if playerData then
		local ranking = playerData.Ranking
		local battlePass = playerData.BattlePass
		if ranking.CurrentSeason.Value == CURRENT_SEASON then
			-- update level from xp
			local lastLevel = ranking.Level.Value
			repeat
				local requiredXP = XPForLevel(ranking.Level.Value + 1)
				if ranking.LevelXP.Value >= requiredXP then
					ranking.LevelXP.Value = ranking.LevelXP.Value - requiredXP
					ranking.Level.Value = ranking.Level.Value + 1
					script.Parent.BattlePassScript.LevelUp:Fire(player, ranking.Level.Value)
				end
			until ranking.LevelXP.Value < requiredXP

			if ranking.Level.Value > lastLevel then
				REMOTES.LevelUp:FireClient(player)
			end
		else
			-- transfer level to rank
			ranking.Rank.Value = ranking.Rank.Value + ranking.Level.Value
			-- reset level and level xp
			ranking.Level.Value = 0
			ranking.LevelXP.Value = 0
			-- reset xp boost
			battlePass.XPBoost.Value = 0
			-- update to current season
			ranking.CurrentSeason.Value = CURRENT_SEASON
		end
	end
end

local function SkipTier(player)
	local playerData = PLAYER_DATA:FindFirstChild(player.Name)
	if playerData then
		if playerData.Ranking.Level.Value < 100 then
			playerData.Ranking.Level.Value = playerData.Ranking.Level.Value + 1
			script.Parent.BattlePassScript.LevelUp:Fire(player, playerData.Ranking.Level.Value)
			REMOTES.LevelUp:FireClient(player)
			return true
		end
	end
	return false
end
