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

Can't pick random player from team?

Asked by 3 years ago

So I have a variable that is a random player from a team called 'Playing'

local randomteamplr = game.GetService("Teams").Playing:GetPlayers()[math.random(1, #game.GetService("Teams").Playing:GetPlayers())] --this is all on the same line

then I wanted to make a function that would change that variables value to another random player from that team. (I don't care if it has a chance to be the same one.)

local function pickPlayer()
    randomteamplr = game.GetService("Teams").Playing:GetPlayers()[math.random(1, #game:GetService("Teams").Playing:GetPlayers())] -- everything in this function is also all on the same line
end

The script says there's no error but when I play I get this error:

invalid argument #2 to 'random' (interval is empty)

Not sure what I'm doing wrong?

0
Does :GetPlayers() work with teams? Why not try :GetChildren() Jay123abc2 241 — 3y
0
It worked for me without any errors when I try using it in a localscript. StayMarkus 0 — 3y
0
ill try that super00rocket 27 — 3y
0
nope super00rocket 27 — 3y

Answer this question