Teams:GetPlayers() returning Instance Objects and not Player Objects

Hello, I have been trying to make an script in which it requires to get the players of an certain team and their character. However, I have been unable to do this, since the script for some reason returns Instance objects when I do Team:GetPlayers() instead of player objects, making me unable to get the player character.
Here is the line of code.

local homeTeamPlayers = Teams["Home Team"]:GetPlayers() --get list of home team players
	local awayTeamPlayers = Teams["Away Team"]:GetPlayers() --get list of away team players

And here is what im trying to do

	for i,v in pairs (awayTeamPlayers) do
		print(v.Character)
		print(v)
		print(tostring(v.Character))
		local kitClone = awayKit:Clone()
		if(v.Character:FindFirstChild("Shirt")) then
			v.Character:FindFirstChild("Shirt").ShirtTemplate = randomKit2
		else
			kitClone.Parent = v.Character
		end
		
	end

Could you please show the entire script please? When you do print(v.Character) what shows up in console?

print(v.Character) gives me null, but print(v) gives me the name of the player

function module.giveTeamKit()
	local homeTeamPlayers = Teams["Home Team"]:GetPlayers() --get list of home team players
	local awayTeamPlayers = Teams["Away Team"]:GetPlayers() --get list of away team players
	local randomKit1 = kitIDs[math.random(1,#kitIDs)]
	local randomKit2 = kitIDs[math.random(1,#kitIDs)]
	local homeKit = Instance.new("Shirt")
	homeKit.Name = "HomeKit"
	local awayKit = Instance.new("Shirt")
	awayKit.Name = "AwayKit"
	homeKit.ShirtTemplate = randomKit1
	awayKit.ShirtTemplate = randomKit2
	for i,v in homeTeamPlayers do
		local kitClone = homeKit:Clone()
		kitClone.Parent = v.Character
	end
	for i,v in pairs (awayTeamPlayers) do
		print(v.Character)
		print(v)
		print(tostring(v.Character))
		local kitClone = awayKit:Clone()
		if(v.Character:FindFirstChild("Shirt")) then
			v.Character:FindFirstChild("Shirt").ShirtTemplate = randomKit2
		else
			kitClone.Parent = v.Character
		end
		
	end
end

Since .character is technically an instance, it wouldn’t even be able to be properly printed. Are there any errors that show up?

18:35:35.947 nil - Server - ModuleScript:35
This is what happens when I print(v.Character)

Try using :GetChildren and see if that works instead of get players

Now it isn’t working at all, it isn’t doing anything.

v.Character is nil if the player is dead or if the player’s character hasn’t loaded in yet

So how would I wait until characters have loaded in for this script to execute?

When do you run the script?


I think you should skip over players that haven’t loaded in yet, so they don’t get put into a team and maybe even a game without knowing about it.

You are not returning the players from the module script… add return (value you want to give to the script calling). Also since print(v) == the players name you could reference the player by typing Players[v].Character for example.