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

Why is this script doing this?

Asked by
wjs3456 90
9 years ago

The script I have here I am using to(at random) select someone to be on the orange team. The problem is that when there are two(or more) people on the game it runs it for the amount of players on the game.

players = game.Players:GetPlayers()
for i,v in pairs(game.Players:GetPlayers()) do
if #players >= 1 then
    first_infected = players[math.random(1, #players)]
    first_infected.TeamColor = BrickColor.new("Bright orange")--This is all in a function so it will run.

So my question is: How can I make it so it only changes the team of one person at one time? Hope this make sense

Thanks

1 answer

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

Simply remove your loop. There isn't a reason for there to be a loop here; no operation is "per player", there is just a single thing happening that happens to use a list of players.

0
Facepalm on my part. Thanks... again :) wjs3456 90 — 9y
Ad

Answer this question