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

Random player from team events?

So, I am trying to make a survival game. There are three teams, Red (eliminated) Orange (Alive) and Yellow (Eliminator). I am trying to make a script where one person from the alive team becomes an eliminator. I know how to make a random player chooser script, but I don't want anyone from the eliminated team to get chosen. I tried out a script but it doesn't work. Does anyone know whats wrong with this script? Thanks, taxicar24

local ChosenPlayer = game.Teams["Neon orange"]:GetPlayers()[math.random(1,#game.Teams["Neon orange"]:GetPlayers())]
	ChosenPlayer.TeamColor = BrickColor.new("New Yeller")

1 answer

✓ Accepted answer

Can't test it right now, but I believe the following code works. Let me know if it doesn't.

local players = game.Teams["Neon orange"]:GetPlayers()
local ChosenPlayer = players[math.random(#players)]

ChosenPlayer.TeamColor = BrickColor.new("New Yeller")

6 comments

0

So I copied and tested that script, and it still did not work.

0

Can you share with me what shows up in the output so I can diagnose it better?

0

Im not very good with outputs, but it does say "Neon orange is not a valid member of Teams." Everything else has nothing to do with this script whatsoever.

0

Then thats because you gotta put the name of your team in between the brackets next to 'game.Teams[]' at the first line, not its color. So yeah, "Neon orange" shouldn't go there but rather the name of the team object. What is said team called?

0

OMG IT WORKS TYSM!!!!!!!!

0

No problem! Anytime :)

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