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

Finding the Torso in a Player in Workspace?

Asked by
Qorm 100
10 years ago
player=game.Workspace.Name
player.Torso.Anchored=true

Trying to Anchore a player's torso.. I'm not quite sure how though. New at Players and findFirstChild so don't judge D: Sorry for the stupid question.

1 answer

Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

To reply to the other post, LocalScripts don't run in Workspace.


The problem with your code is that your avatar's name isn't 'Name'.

The dot, ., will search for a child or a property.

If there is both a child and a property with the same name, it will go to the property.

Since Workspace (and all other objects) have a Name property,

game.Workspace.Name

will literally return the string "Workspace".


To find a character in Workspace, using your method, you must know the character's Name, so you can search for that character via a dot.

game.Workspace.Perci1

To anchor every player's torso, regardless of their name, we can use a LocalScript. However, that LocalScript must be placed inside StarterGui, so that it will later be cloned into every player's PlayerGui. LocalScripts only run inside a Player or a Character.

repeat wait() until game.Players.LocalPlayer.Character ~= nil
game.Players.LocalPlayer.Character:WaitForChild("Torso").Anchored = true

Remember that server scripts cannot use the LocalPlayer property of Players. This is because server scripts run on the server, while LocalScripts run on your computer. This allows them to access which Player's computer they are running on, letting game.Players.LocalPlayer to work.

WaitForChild() simply delays the script until the Torso exists, in case it's not loaded yet. The repeat loop will delay the script until the Character exists.

These two things may not always be necessary but will help prevent errors.

Ad

Answer this question