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 » ROBLOX Studio
Home Search
 

Re: Using Variables and the Parent/Children System

Previous Thread :: Next Thread 
alty1234 is not online. alty1234
Joined: 04 Nov 2011
Total Posts: 13
30 Jul 2014 10:42 AM
Say I have a player's name which I am storing under the variable "playerName". How would I obtain the torso of said character using the parent/child ssytem? I've tried the below code, which does not work:

local playerTorso = game.Players.playerName.Character:FindFirstChild("Torso")

Thanks in advance.
Report Abuse
AdmiralLennox is not online. AdmiralLennox
Joined: 19 Jun 2013
Total Posts: 378
30 Jul 2014 11:59 AM
This is a question for Scripting Helpers, but if playerName is a string then you might try:

game.Players[playerName].Character:FindFirstChild("Torso")
Report Abuse
alty1234 is not online. alty1234
Joined: 04 Nov 2011
Total Posts: 13
01 Aug 2014 05:15 AM
Ok, so I've gone and replaced that line from my previous post with:

local playerTorso = game.Players[playerName].Character:FindFirstChild("Torso")

which is then returning this error message in the output window:

Workspace.TargetA.ProximityRing.Script:44: bad argument #2 to '?' (string expected, got userdata)

Based on this, do I need to convert playerName into a String data type first? Cos I'm printing playerName (using print(playerName)) into the output window in the line before this in order to check it holds the correct name, and I thought youcould only print number values and strings into the output window.
Report Abuse
AdmiralLennox is not online. AdmiralLennox
Joined: 19 Jun 2013
Total Posts: 378
01 Aug 2014 06:59 AM
playerName should be a string already, assuming you did it right. Are you sure you're setting playerName equal to the player's name, and not the player itself?
Report Abuse
alty1234 is not online. alty1234
Joined: 04 Nov 2011
Total Posts: 13
03 Aug 2014 08:32 AM
Yeah, you were right, I looked into the part of the script that was assigning the value to "playerName" and found that it was assigning the player itself. I've fixed it now. Thanks!
Report Abuse
AdmiralLennox is not online. AdmiralLennox
Joined: 19 Jun 2013
Total Posts: 378
03 Aug 2014 02:52 PM
No problem, glad I could be of help.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » ROBLOX Studio
   
 
   
  • 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