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


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
