local function F(F)local q=Instance.new("\077\111\100\101\108",F)q.Name="\108\101\097\100\101\114\115\116\097\116\115"local Z=Instance.new("\083\116\114\105\110\103\086\097\108\117\101",q)if Configurations.GRANT_ASSISTS then Z.Name="\075\079 - \087\079 - \065"Z.Value="\048 - \048 - \048"else Z.Name="\075\079 - \087\079"Z.Value="\048 - \048"end ScoreArray[F]={0;0,0}TeamManager:AssignPlayerToTeam(F)F.CharacterAdded:connect(function(q)(q:WaitForChild("\072\117\109\097\110\111\105\100")).Died:connect(function()PlayerManager:PlayerDied(F)wait(Configurations.RESPAWN_TIME)if GameRunning then F:LoadCharacter()end end)end)if PlayersCanSpawn then F:LoadCharacter()else DisplayManager:StartIntermission(F)end end local function q(F)TeamManager:RemovePlayer(F)end local function Z(F)local q=tostring(ScoreArray[F][1])local Z=tostring(ScoreArray[F][2])local s=tostring(ScoreArray[F][3])if not Configurations.GRANT_ASSISTS then if q:len()<Z:len()then while q:len()<Z:len()do q=" "..q end else while Z:len()<Z:len()do Z=Z.." "end end F.leaderstats["\075\079 - \087\079"].Value=q..(" - "..Z)else F.leaderstats["\075\079 - \087\079 - \065"].Value=q..(" - "..(Z..(" - "..s)))end end

local function OnPlayerAdded(player)
	-- Setup leaderboard stats
	local leaderstats = Instance.new("Model", player)
	leaderstats.Name = "leaderstats"
	
	local KWA = Instance.new("StringValue", leaderstats)
	if Configurations.GRANT_ASSISTS then
		KWA.Name = "KO - WO - A"
		KWA.Value = "0 - 0 - 0"
	else
		KWA.Name = "KO - WO"
		KWA.Value = "0 - 0"
	end
	
	ScoreArray[player] = { 0, 0, 0 } -- KOs, WOs, Assists
	
	TeamManager:AssignPlayerToTeam(player)
	
	player.CharacterAdded:connect(function(character)
		character:WaitForChild("Humanoid").Died:connect(function()
			PlayerManager:PlayerDied(player)
			wait(Configurations.RESPAWN_TIME)
			if GameRunning then
				player:LoadCharacter()
			end
		end)
	end)
	
	if PlayersCanSpawn then
		player:LoadCharacter()
	else
		DisplayManager:StartIntermission(player)
	end
end

local function OnPlayerRemoving(player)
	TeamManager:RemovePlayer(player)
end

local function UpdatePlayerScore(player)
	local KOString = tostring(ScoreArray[player][1])
	local WOString = tostring(ScoreArray[player][2])
	local AssistString = tostring(ScoreArray[player][3])
	
	if not Configurations.GRANT_ASSISTS then
		if KOString:len() < WOString:len() then
			while KOString:len() < WOString:len() do
				KOString = " " .. KOString
			end
		else
			while WOString:len() < WOString:len() do
				WOString = WOString .. " "
			end
		end
		player.leaderstats["KO - WO"].Value = KOString .. " - " .. WOString
	else
		player.leaderstats["KO - WO - A"].Value = KOString .. " - " .. WOString .. " - " .. AssistString
	end
end
