Advertisement
otorp2

roblox get retrieve lefthand

Jun 28th, 2017
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. You'll first want to get the player themselves. Since this is a LocalScript then it is as simple as using the LocalPlayer property of the Players service.
  2.  
  3. Next, you'll want to get their character. Player objects have a nice property called Character. Caution, however! As this property might be nil!
  4. If the player is in the process of [re]spawning, for example, their character may not exist yet. Although, since your script is going to be in a GUI...
  5. I guess it's safe to assume the player will be alive at that time, as to see a GUI a player first have to spawn.
  6.  
  7. Next, you can retrieve the player's bodypart using character:FindFirstChild("Bodypart"). Not character.Bodypart, this will error if the bodypart does
  8. not exist! Which can be the case if they get their legs blown off, for example, or if they die and their head falls under the minimum height limit. You
  9. don't want to use character:WaitForChild("Bodypart") either, unless you absolutely need to.
  10.  
  11. The final step before using that Bodypart is to make sure it exists. FindFirstChild won't error if the object you are looking for does not exist, but if it
  12. doesn't it will still return nil! And we cannot retrieve properties or call methods on a nil value, so we will have to make sure FindFirstChild's return value
  13. is non-nil, just like we did with the character:
  14. local character = game.Players.LocalPlayer.Character
  15.  
  16. if character then
  17. -- the character exists.
  18. local bodypart = character:FindFirstChild("Bodypart")
  19.  
  20. if bodypart then
  21. -- 'bodypart' exists; proceed.
  22. end
  23. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement