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

How to make a random person "it"?

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()

2 comments

0

What;s the problem? That looks fine.

0

I don't know its just whenever I try it it wont work. Would it matter that the orange team isnt auto assignable?

2 answers

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.

3 comments

0

If you didn't want to add the while loop like that, simply delete that part and the third end.

0

Nevermind about the wait thing, Wait() works as well. xD

0

Thanks you very much it worked :)

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()

1 comment

0

Thanks you very much it worked :)

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