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 choose a random player from the opposite team?

ok so basically this is an event, and when it fires, i want a random person from the other team to freeze, but it doesn't work because it's nil value. is there a way i can fix it to ensure it chooses a player from the other team?

if plr.Team == game.Teams.Blue then

repeat
local randomPlayer = game.Players:GetPlayers()[math.random(1,#game.Players:GetPlayers())]
wait()
until
randomPlayer.Team == game.Teams.Red
local freeze = game.Lighting.Freeze:Clone()
freeze.Parent = randomPlayer.Character
randomPlayer.Character.HumanoidRootPart.Anchored = true
wait(8)
randomPlayer.Character.HumanoidRootPart.Anchored = false
freeze:Remove()
elseif plr.Team == game.Teams.Red then
local randomPlayer = game.Players:GetPlayers()
repeat
local randomPlayer = game.Players:GetPlayers()[math.random(1,#game.Players:GetPlayers())]
wait()
until
randomPlayer.Team == game.Teams.Blue
local freeze = game.Lighting.Freeze:Clone()
freeze.Parent = randomPlayer.Character
randomPlayer.Character.HumanoidRootPart.Anchored = true
wait(8)
randomPlayer.Character.HumanoidRootPart.Anchored = false
freeze:Remove()

1 answer

✓ Accepted answer

Well first of all you can just do

local Team = game.Teams.Blue:GetPlayers()
local Chosen = Team[math.random(1, #Team)
Chosen.Team = game.Teams.Red

3 comments

0

is this supposed to switch a player from blue to red team?

0

Yes it changes a random players team from blue to red. If it works make sure to mark it as the answer!

0

i meant that i wanted to choose a person from a different team but the 2 first line works!

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