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

How do I team one random player to the "Monster" team?

I'm trying to make a horror game where four survivors must complete four tasks and enter a safe room, while being pursued by a monster. I want one player at random to be chosen as the monster, while four others have to be the survivors. I used this script to do so, and I made the "Survivors" team auto-assignable. The script doesn't work in studio or in game.

local monster = game.Teams.Monster
local Players = game:GetService("Players")


function onPlayerAdded(player)
	local mon = monster:GetPlayers()
	if mon == 0 then
		player.TeamColor = BrickColor.new("Really red") --team color of monster
	end
end

Players.PlayerAdded:connect(onPlayerAdded)

for _,player in pairs(Players:GetPlayers()) do --I read on the wiki that studio loads players before scripts, this accounts for that.
     onPlayerAdded(player)
end

Any help? Thanks.

1 answer

✓ Accepted answer
local Plrs = game.Players:GetPlayers() -- Add all players to Plrs table

Plr1 = Plrs[math.random(1,#Players)] -- Get a player, this player is defined under Plr1

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