Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Random player from team events?

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago

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")
0
So I copied and tested that script, and it still did not work. taxicar24 19 — 4y
0
Can you share with me what shows up in the output so I can diagnose it better? Le_Teapots 913 — 4y
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. taxicar24 19 — 4y
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? Le_Teapots 913 — 4y
View all comments (2 more)
0
OMG IT WORKS TYSM!!!!!!!! taxicar24 19 — 4y
0
No problem! Anytime :) Le_Teapots 913 — 4y
Ad

Answer this question