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

How to make a random person "it"?

Asked by
wjs3456 90
9 years ago

I want to make it so that when a new game starts 15 seconds in a person will be randomly selected to be it which will make them be on the orange team. Very much like a hide and seek script. Here's the script.

function FirstInfected()

Wait(15)
players=game.Players:GetPlayers()
while player>=1 do
    first_infected=players[math.random(1, #players)]
    first_infected.TeamColor=BrickColor.new("Bright orange")
end
end



FirstInfected()
0
What;s the problem? That looks fine. Perci1 4988 — 9y
0
I don't know its just whenever I try it it wont work. Would it matter that the orange team isnt auto assignable? wjs3456 90 — 9y

2 answers

Log in to vote
1
Answered by 9 years ago
function FirstInfected()
while true do --I'm assuming you want to loop this every 15 seconds...? If not delete this part and the third end
wait(15)
players=game.Players:GetPlayers()
    if #players >= 1 then --# is the length of the table
    first_infected=players[math.random(1, #players)]
    first_infected.Neutral = false 
    first_infected.TeamColor= BrickColor.new("Bright orange")
end
end
end
FirstInfected()


The first problem was that in line 3, Wait(15) was supposed to be wait(15). Second, on line 5, you wrote player, when the table name was players. Third, you had to add #players, otherwise, as the output states, you're comparing a table with a number. Finally, if you didn't add a wait inside your while loop, it will crash the whole server.

0
If you didn't want to add the while loop like that, simply delete that part and the third end. mrgeorge12345 45 — 9y
0
Nevermind about the wait thing, Wait() works as well. xD mrgeorge12345 45 — 9y
0
Thanks you very much it worked :) wjs3456 90 — 9y
Ad
Log in to vote
1
Answered by
RedCombee 585 Moderation Voter
9 years ago

Okay. Two things.

First is your while loop. It currently can't run because players will never be greater than 1 based on how you displayed it.

Correct code:

function FirstInfected()
Wait(15)
players=game.Players:GetPlayers()
while #players >= 1 do -- You have to have the pound or else it won't work, and whatever follows must match the name of your function perfectly.
wait() -- You need some kind of wait here so your script doesn't crash
first_infected=players[math.random(1, #players)]
first_infected.TeamColor=BrickColor.new("Bright orange")
end
end
FirstInfected()
0
Thanks you very much it worked :) wjs3456 90 — 9y

Answer this question