|
| 09 Nov 2013 04:43 PM |
| What would be the way to get, say, the backpack of all the players? |
|
|
| Report Abuse |
|
|
|
| 09 Nov 2013 04:44 PM |
function Child(Player) --Your code end
for i,v in pairs(game:service'Players':children()) do Child(v) end |
|
|
| Report Abuse |
|
|
|
| 09 Nov 2013 04:46 PM |
| There's no like players = game.Players:AllChildren() or something like that, and I could do players.Backpack? |
|
|
| Report Abuse |
|
|
Kaffeine
|
  |
| Joined: 27 Oct 2013 |
| Total Posts: 230 |
|
|
| 09 Nov 2013 04:50 PM |
function getBackpacks() backpacks = { };
for _, p in pairs(game.Players:GetPlayers()) do if (p.Backpack) then backpacks[p.Name] = p.Backpack; else backpacks[p.Name] = false; end; end;
return backpacks; end;
backpacks = getBackpacks();
for _, b in pairs(backpacks) do -- your code end; |
|
|
| Report Abuse |
|
|
Kaffeine
|
  |
| Joined: 27 Oct 2013 |
| Total Posts: 230 |
|
|
| 09 Nov 2013 04:50 PM |
@joshua y u use deprecated methods? |
|
|
| Report Abuse |
|
|
|
| 09 Nov 2013 04:53 PM |
@Kaffeine-
So if I put this in a part of the script as a separate function, could I access the backpacks with a variable in other functions? |
|
|
| Report Abuse |
|
|
|
| 09 Nov 2013 04:54 PM |
| And if I wanted to say like a certain child of the backpacks would I have to do more complicated scripting or could I just say backpacks.Tool? |
|
|
| Report Abuse |
|
|
|
| 09 Nov 2013 04:55 PM |
| I would rather not type out :GetChildren() |
|
|
| Report Abuse |
|
|
Kaffeine
|
  |
| Joined: 27 Oct 2013 |
| Total Posts: 230 |
|
|
| 09 Nov 2013 04:55 PM |
Yes. Example:
function yourFunction() backpacks = getBackpacks();
for n, b in pairs(backpacks) do if (not b) then print("Player " .. n .. " hasn't a backpack! :o") else -- your code end; end; end; |
|
|
| Report Abuse |
|
|
Kaffeine
|
  |
| Joined: 27 Oct 2013 |
| Total Posts: 230 |
|
|
| 09 Nov 2013 04:57 PM |
@Josh It's still deprecated, and only a few more keystrokes, which shouldn't take all of a few milliseconds.
@OP You could just do b.ToolName
but to make sure your script doesn't error, I'd suggest something like if (b:FindFirstChild('ToolName') then -- your code end; |
|
|
| Report Abuse |
|
|
|
| 09 Nov 2013 04:58 PM |
| Is there a way I could just put some of this stuff in one section of the script to assign the backpacks and PlayerGuis variables, then just do the rest of the coding using those variables or would I have to use this function? |
|
|
| Report Abuse |
|
|
Kaffeine
|
  |
| Joined: 27 Oct 2013 |
| Total Posts: 230 |
|
|
| 09 Nov 2013 05:00 PM |
| You wouldn't have to use the function, but it is just easier to put it in one if you are going to use it more than once in your code. |
|
|
| Report Abuse |
|
|
|
| 09 Nov 2013 05:11 PM |
| I'm kind of confused now. How do I access the backpacks later on then? |
|
|
| Report Abuse |
|
|
| |
|