Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to access body parts of player through local scripts?

Asked by 3 years ago

Hello! I would like to know how to access body parts of the local player in a local script, I'm not sure if this is complicated or easy, and I this is what I was told before:

game.Players.LocalPlayer.Character.LeftArm

I'm not sure how to do this, so any help is appreciated, thanks.

1 answer

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

So, for accessing the parts, there's two different circumstances you would do this in:

  1. A script that starts with the player

  2. A script that starts with the character

If it starts with the character, your method of game.Players.LocalPlayer.Character.<NAMEHERE> should work perfectly fine, as the part is always there in the eyes of the script.

However, if the script runs from when the player joins the server, your player will have **multiple **LeftArms, e.c.t. for each death/respawn. To negate this, the script should wait for each character created, then grab the part after.

Here's the code I used, inside of the StarterPlayerScripts, to get each left foot, of the R15 model.

game.Players.LocalPlayer.CharacterAdded:connect(function()
    print("Character added")
    local LeftFoot = game.Players.LocalPlayer.Character:WaitForChild("LeftFoot")
    print(LeftFoot)
    --Continue your script here...
end)

To change the part, simply replace the name in the " " space, with the name of the required part.

If you have any issues, please do reply. Hope I could be of help.

1
Thanks! StirSavvy 38 — 3y
1
No problem, glad I could help! :) NinjaMandalorian 252 — 3y
Ad

Answer this question