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

How do i choose a random player from the opposite team?

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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
0
is this supposed to switch a player from blue to red team? Thescrubbyman 2 — 5y
0
Yes it changes a random players team from blue to red. If it works make sure to mark it as the answer! araltan2002 47 — 5y
0
i meant that i wanted to choose a person from a different team but the 2 first line works! Thescrubbyman 2 — 5y
Ad

Answer this question