Leaderboard Help

wait(1)
game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)
local players = game:GetService("Players")
local template = script.Parent:WaitForChild("Template")
template.Visible = false
local cardFolder = script.Parent:WaitForChild("PlayerCards")
local RS = game:GetService("ReplicatedStorage")
local AddPlayer = RS.Events:WaitForChild("AddPlayer")
local player = players.LocalPlayer

local nationAppearance = {
	nation0 = {id = "http://www.roblox.com/asset/?id=4546505330"; pre = "A"};
	nation1 = {id = "http://www.roblox.com/asset/?id=4546504176"; pre = "B"};
	nation2 = {id = "http://www.roblox.com/asset/?id=4546504760"; pre = "C"};
	nation3 = {id = "http://www.roblox.com/asset/?id=4546505025"; pre = "D"};	
}

local cards = {}
function playerAdded(p)
	
	local card = template:Clone()
	
	local Squad = p.leaderstats:WaitForChild("Squad")
	local MagicKnight = p.leaderstats:WaitForChild("MagicKnight")
	local FN = p:WaitForChild("FirstName")
	
	local function setSquad()
		if Squad.Value == "Black Bulls" then
			card.NationID.Image = "rbxassetid://6565114368"
			card.Username.BackgroundColor = BrickColor.Black()
			card.Username.BackgroundTransparency = 0.5
			print("Squad Changed")
		elseif Squad.Value == "Golden Dawn" then
			card.NationID.Image = "rbxassetid://6599249876"
			card.Username.BackgroundColor = BrickColor.new("New Yeller")
			card.Username.BackgroundTransparency = 0.5
		elseif Squad.Value == "Silver Eagle" then
			card.NationID.Image = "rbxassetid://6598950456"
			card.Username.BackgroundColor = BrickColor.new("Wheat")
			card.Username.BackgroundTransparency = 0.5
		elseif Squad.Value == "Blue Rose" then
			card.NationID.Image = "rbxassetid://6598992885"
			card.Username.BackgroundColor = BrickColor.new("Really blue")
			card.Username.BackgroundTransparency = 0.5
		elseif Squad.Value == "Crimson Lion" then
			card.NationID.Image = "rbxassetid://6598998119"
			card.Username.BackgroundColor = BrickColor.new("Really red")
			card.Username.BackgroundTransparency = 0.5
		elseif Squad.Value == "Green Mantis" then
			card.NationID.Image = "rbxassetid://6599003599"
			card.Username.BackgroundColor = BrickColor.new("Bright green")
			card.Username.BackgroundTransparency = 0.5
		elseif Squad.Value == "Coral Peacock" then
			card.NationID.Image = "rbxassetid://6599014259"
			card.Username.BackgroundColor = BrickColor.new("Hot pink")
			card.Username.BackgroundTransparency = 0.5	
		elseif Squad.Value == "Purple Orca" then
			card.NationID.Image = "rbxassetid://6599021337"
			card.Username.BackgroundColor = BrickColor.new("Royal purple")
			card.Username.BackgroundTransparency = 0.5		
		elseif Squad.Value == "Aqua Deer" then
			card.NationID.Image = "rbxassetid://6599031156"
			card.Username.BackgroundColor = BrickColor.new("Light blue")
			card.Username.BackgroundTransparency = 0.5		
		end
	end
	
	setSquad()
	card.Username.Text = FN.Value.. " ".. MagicKnight.Value
	card.Visible = true
	card.Parent = cardFolder
	
	Squad.Changed:Connect(function()
		setSquad()
	end)
	
	MagicKnight.Changed:connect(function()
		card.Username.Text = FN.Value.. " ".. MagicKnight.Value
	end)
	
	FN.Changed:Connect(function()
		card.Username.Text = FN.Value.. " ".. MagicKnight.Value
	end)
	
	card.Username.MouseEnter:Connect(function()
		card.Username.Text = p.Name
		card.Username.MouseLeave:Wait()
		card.Username.Text = FN.Value.. " ".. MagicKnight.Value
	end)
	
	table.insert(cards, {
		object=card;
		player=p;	
	})
end


--players.PlayerAdded:Connect(p)
--players.PlayerAdded:Connect(function(p)
	--playerAdded(p)
--end)

	
players.PlayerRemoving:Connect(function(p)
	for i ,v in pairs(cards) do
		if v.player == p then
			v.object:Destroy()
			table.remove(cards, i)
		end
	end
end)



	for _,v in pairs(players:GetPlayers()) do
		coroutine.wrap(playerAdded)(v)
	end

local frame = script.Parent.Parent.Parent
game:GetService("UserInputService").InputBegan:Connect(function(input, processed)
	if not processed and input.KeyCode == Enum.KeyCode.Tab then
		frame.Visible = not frame.Visible
	end
end)

I scripted a leaderboard it kind of works. When there players already in the server it shows them ,but when a player joins the server it won’t work.

How would I make a function run when a player join the games. I tried using game.Players.PlayerAdded:Connect(function() etc. It didn’t work. Any ideas?

Squad refers to a IntValue. You can’t compare its Value with a string, because it can only be a number. Read this article for more info.