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

How do I refer to players of one team?

How do I use only players of one team in a script?

For example, the team name is "Fighters" and I want to use a function that teams anyone in that team back to Spectators if Fighters has one or less player. If one player then announce the winner, if 0 then announce a tie.

Fight = game.Workspace.Fight.Value
GameVal = game.Workspace.GameVal.Value
Fighters = game.Teams.Fighters:GetChildren()

function finish()
	if GameVal == true and #Fighters == 1 then
		Fighter = Fighters.FindFirstChild.Name
		m = Instance.new("Hint")
		m.Parent = game.Workspace
		m.Text = Fighter.."has won the round!"
		GameVal = false
		wait(3)
		m:remove()
	elseif GameVal == true and #Fighters == 0 then
		m = Instance.new("Hint")
		m.Parent = game.Workspace
		m.Text = "There has been a tie!"
		wait(3)
		m:remove()
	end
end

Fight.Changed:connect(finish)

Will this work or how should I approach this?

1 answer

Fight = game.Workspace.Fight.Value
GameVal = game.Workspace.GameVal.Value
Fighters = game.Teams.Fighters:GetChildren()

function finish()
	Fighters = game.Teams.Fighters:GetChildren() --Re-Defining Fighters value
	if GameVal == true and #Fighters == 1 then
		Fighter = Fighters --Since there is only one player, it's getting all the children in Fighters, which is just that one player
		m = Instance.new("Hint")
		m.Parent = game.Workspace
		m.Text = Fighter.Name.." has won the round!" --Inserted a space, would have looked like this "Player1has won the round!", also you forgot to have it get the fighter's name, you were trying to get the fighter's player object
		GameVal = false
		wait(3)
		m:remove()
	elseif GameVal == true and #Fighters == 0 then
		m = Instance.new("Hint")
		m.Parent = game.Workspace
		m.Text = "There has been a tie!"
		wait(3)
		m:remove()
	end
end

Fight.Changed:connect(finish)

Try it and tell me how it works! :D

2 comments

0

Oh okay I need another script to work first, can you tell me whether trying to change the team of a whole team works? Like I am trying

0

player = game.Players:GetChildren() player.TeamColor = BrickColor.new("Bright green") would that work? Because its not for me.

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