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