|
| 20 Oct 2015 12:54 PM |
function DisplayManager:ClassDisplay() for _, plrs in pairs(game.Players:GetPlayers()) do print(#game.Players:GetPlayers()) local gui = plrs.PlayerGui:FindFirstChild("ScreenGui") local inormDisp = gui:FindFirstChild("ClassDisplayiNormal") local armedDisp = gui:FindFirstChild("ClassDisplayArmed") local innoDisp = gui:FindFirstChild("ClassDisplayInnocent") --local raiderDisp = gui:FindFirstChild("ClassDisplayRaider") local inorm = plrs[math.random(1,#plrs)] local rndm = plrs[math.random(1,#plrs)] repeat wait() rndm = v[math.random(1,#plrs)] until rndm ~= inorm local armed = rndm return inormDisp end end
Attempt to get length of local 'plrs' (a userdata value) How can i work around this? |
|
|
| Report Abuse |
|
|
|
| 20 Oct 2015 01:01 PM |
Hmm weird, but you can usually get the number of players by going like this:
print(game.Players.NumPlayers) |
|
|
| Report Abuse |
|
|
|
| 20 Oct 2015 01:12 PM |
I call it in another script, and i need to choose randomly from players.
|
|
|
| Report Abuse |
|
|
| |
|
|
| 20 Oct 2015 02:28 PM |
| lol, you did it really wrong. Why would you for loop the players when you want a random player? |
|
|
| Report Abuse |
|
|
|
| 20 Oct 2015 02:33 PM |
If i don't get a new list of players each time, if i like: local players = game.Players:GetPlayers() give me the same value each time its called? I used the for loop as an work around
- "I say no because yes is overrated"
|
|
|
| Report Abuse |
|
|
|
| 20 Oct 2015 02:45 PM |
Bump.
- "I say no because yes is overrated"
|
|
|
| Report Abuse |
|
|
|
| 20 Oct 2015 02:48 PM |
| You're using the len operator on a player object. |
|
|
| Report Abuse |
|
|
|
| 20 Oct 2015 02:48 PM |
| You know you can get a random player from the GetPlayers() right? |
|
|
| Report Abuse |
|
|
|
| 20 Oct 2015 02:51 PM |
Does GetPlayers() have arguments for that
- "I say no because yes is overrated" |
|
|
| Report Abuse |
|
|
|
| 20 Oct 2015 02:52 PM |
| game.Players:GetPlayers()[math.random(1, #game.Players:GetPlayers())] |
|
|
| Report Abuse |
|
|
|
| 20 Oct 2015 02:52 PM |
local players = game.Players:GetPlayers(); local this = players[math.random(#players)]; |
|
|
| Report Abuse |
|
|
| |
|
| |
|
|
| 20 Oct 2015 02:54 PM |
Thanks, and if i returned Two random players instead of one how would i assign each player to a variable?
- "I say no because yes is overrated" |
|
|
| Report Abuse |
|
|
|
| 20 Oct 2015 02:55 PM |
local player = RANDOM_LINE -- That was provided by me
That's literally it |
|
|
| Report Abuse |
|
|
|
| 20 Oct 2015 03:01 PM |
Lets say plrs are defined as the 2 players it would go like this;
local plr1 = [1,#plrs] -- Im really sleepy, so if i am being stoopid blame the sleeping hormones.. zzzzz
local plr2 = [2,#plrs]
- "I say no because yes is overrated" |
|
|
| Report Abuse |
|
|
|
| 20 Oct 2015 03:05 PM |
local players = {}; setmetatable(players, {__call = function() return game.Players:GetPlayers() end});
players.random = function(maxn) local this = {}; local players = players(); while (#players > 0) do if (#this < maxn) then this[#this + 1] = table.remove(players, math.random(#players)); end end return unpack(this); end
local player1, player2 = players.random(2);
I normally use this when selecting more than 1 random player. |
|
|
| Report Abuse |
|
|
|
| 20 Oct 2015 03:07 PM |
local players = {}; setmetatable(players, {__call = function() return game.Players:GetPlayers() end});
players.random = function(maxn) local this = {}; local players = players(); while (#players > 0) do if (#this < maxn) then this[#this + 1] = table.remove(players, math.random(#players)); else break; -- forgot the break statement. end end return unpack(this); end
local player1, player2 = players.random(2); |
|
|
| Report Abuse |
|
|
|
| 20 Oct 2015 03:19 PM |
Thanks both of you!
- "I say no because yes is overrated"
|
|
|
| Report Abuse |
|
|