Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to get names of people on a certain team?

So I am a newbie at lua scripting, But i'm trying to make it so the "hint" displays the players name on the team, but I do not know how to get the player's name on the team, I have tried many things to it, but it does not work, Does anyone have a solution?

1 answer

First we use a for loop to get the players. We use an if statement to see if the player is on a team, then we just use their names.


For Loops

They just loop for a certain amount of time.

for i = 1,10 do--10 times
	
end

You can also do this:

for _,plyr in pairs(game:GetService("Players"):GetPlayers()) do
	print(plyr.Name) --prints the player's name.
end

If Statments

It's basically just saying, "If something happens do this:"

if Bob == Human then
	print("Bob is a human")
end

Names and adding them to strings.

hint.Text = game:GetService("Players").Player1.Name

Hint says:

Player1


TeamColors are BrickColors. So to see if they're on a team, see if they're TeamColor is a certain BrickColor:

game:GetService("Players").Player1.TeamColor = BrickColor.new(127) --Grey


local h = Instance.new("Hint", workspace)

for _,plyr in pairs(game:GetService("Players"):GetPlayers()) do
	if plyr.TeamColor == BrickColor.new("Bright red") then
		h.Text = "Players on the Red team: "
		h.Text = h.Text..plyr.Name
	end
end

--Edit this script. This works but not well. Use what you learned!



Hope this helps!

1 comment

0

Thanks, this has really helped

This discussion is preserved as it was. New answers, comments, and votes are closed.