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: Finding the Player

Previous Thread :: Next Thread 
DJSasuke1963 is not online. DJSasuke1963
Joined: 30 Nov 2012
Total Posts: 1136
16 Jan 2014 12:26 PM
I have created a tool that when it hits a part will display a gui but i want to know how to place the gui within PlayerGui from the model of the player?

gui.Parent = script.Parent.Parent.PlayerGui - Something like this..
Report Abuse
DJSasuke1963 is not online. DJSasuke1963
Joined: 30 Nov 2012
Total Posts: 1136
16 Jan 2014 12:26 PM
- Links to some kind of forum that teaches this part would be great, thanks.
Report Abuse
Kingmouli is not online. Kingmouli
Joined: 28 Sep 2012
Total Posts: 1292
16 Jan 2014 12:30 PM
script.Parent.Equipped:connect(function()
char = script.Parent.Parent -- the player
plyr = game.Players:GetPlayerFromCharacter(char) -- find the plyr corresponding to the char
--code
end)

To access the PlayerGui you would use plyr.PlayerGui
Report Abuse
DaMrNelson is not online. DaMrNelson
Joined: 27 Jul 2009
Total Posts: 4405
16 Jan 2014 12:31 PM
If you are Parenting the GUI to the Player holding the Tool, I would recommend moving your Script over to a LocalScript. With a LocalScript, you can use this:

gui.Parent = game.Players.LocalPlayer.PlayerGui

LocalPlayer is the Player that the LocalScript belongs to, and is being run by. In other words, if the Player is holding a Tool with a LocalScript that uses LocalPlayer, the LocalPlayer will be the Player holding the Tool.

If you cannot do this, then I think it's time for a lesson in the game hierarchy. The Parent refers to the Instance that another Instance resides in. For example, game.Workspace.Part.Parent is Workspace.
Understanding that, you also need to know that the Tool is stored within the Character (not the Backpack) when it is open. Therefore, if the Script is directly inside of the Tool, you can do this:

local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent) -- script.Parent will be the Tool, and script.Parent.Parent will be the Character
gui.Parent = player.PlayerGui

Wiki Profile: http://wiki.roblox.com/index.php/User:Nelson
Report Abuse
Kingmouli is not online. Kingmouli
Joined: 28 Sep 2012
Total Posts: 1292
16 Jan 2014 12:32 PM
Oh you mean when you touch the part with the tool? You should use the GetPlayerFromCharacter method as used above.
Report Abuse
DaMrNelson is not online. DaMrNelson
Joined: 27 Jul 2009
Total Posts: 4405
16 Jan 2014 12:33 PM
@Kingmouli
I wasn't completely sure on what he meant, so I just tried to educate him on the whole topic ;)

Wiki Profile: http://wiki.roblox.com/index.php/User:Nelson
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