Creating Playercards for everyone that is on a team

I am creating a player selection system and I want to create a GUI that displays a list of all players who are on a certain team. However, the current script is generating a list of all players in the game for some clients, while for others it only generates a player card for one player.

local Values = game.ReplicatedStorage.Values
local Player = game.Players.LocalPlayer
local PlayersList = game.Players:GetPlayers()

function createCard()
	for i, player in pairs(PlayersList) do
		if player.Team == game.Teams.Fans then
			local PlayerCard = script.Parent.PlayerCardTemplate:Clone()
			PlayerCard.Parent = script.Parent.NeutralPlayers
			PlayerCard.PlayerName.Text = player.Name
			PlayerCard.Name = player.Name
			PlayerCard.Visible = true
			PlayerCard.MouseButton1Click:Connect(function()
		game.ReplicatedStorage.Events.RemoteEvent:FireServer(PlayerCard.PlayerName.Text)
			end)
		end
	end
end

game.ReplicatedStorage.Events.RemoteEvent.OnClientEvent:Connect(function(CurrentStatus, PickedPlayer, PickingTeam)
	local function UpdatePlayers()
		if CurrentStatus == "Start Round" then
			createCard()
		end
	end
	UpdatePlayers()
end)
1 Like

did u try getting the players when calling the function

function createCard()
local PlayersList = game.Players:GetPlayers()
	for i, player in pairs(PlayersList) do
		if player.Team == game.Teams.Fans then
			local PlayerCard = script.Parent.PlayerCardTemplate:Clone()
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.