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
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
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.