generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: How would I get a child of each player?

Previous Thread :: Next Thread 
Isometricity is not online. Isometricity
Joined: 26 Oct 2011
Total Posts: 438
09 Nov 2013 04:43 PM
What would be the way to get, say, the backpack of all the players?
Report Abuse
JoshuaKempfert is not online. JoshuaKempfert
Joined: 16 Feb 2013
Total Posts: 2407
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
Isometricity is not online. Isometricity
Joined: 26 Oct 2011
Total Posts: 438
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 is not online. 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 is not online. Kaffeine
Joined: 27 Oct 2013
Total Posts: 230
09 Nov 2013 04:50 PM
@joshua
y u use deprecated methods?
Report Abuse
Isometricity is not online. Isometricity
Joined: 26 Oct 2011
Total Posts: 438
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
Isometricity is not online. Isometricity
Joined: 26 Oct 2011
Total Posts: 438
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
JoshuaKempfert is not online. JoshuaKempfert
Joined: 16 Feb 2013
Total Posts: 2407
09 Nov 2013 04:55 PM
I would rather not type out :GetChildren()
Report Abuse
Kaffeine is not online. 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 is not online. 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
Isometricity is not online. Isometricity
Joined: 26 Oct 2011
Total Posts: 438
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 is not online. 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
Isometricity is not online. Isometricity
Joined: 26 Oct 2011
Total Posts: 438
09 Nov 2013 05:11 PM
I'm kind of confused now. How do I access the backpacks later on then?
Report Abuse
Isometricity is not online. Isometricity
Joined: 26 Oct 2011
Total Posts: 438
09 Nov 2013 05:22 PM
Bump
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image