Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.
- Next, you'll want to get their character. Player objects have a nice property called Character. Caution, however! As this property might be nil!
- 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...
- 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.
- Next, you can retrieve the player's bodypart using character:FindFirstChild("Bodypart"). Not character.Bodypart, this will error if the bodypart does
- 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
- don't want to use character:WaitForChild("Bodypart") either, unless you absolutely need to.
- 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
- 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
- is non-nil, just like we did with the character:
- local character = game.Players.LocalPlayer.Character
- if character then
- -- the character exists.
- local bodypart = character:FindFirstChild("Bodypart")
- if bodypart then
- -- 'bodypart' exists; proceed.
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement