First of all, you do need some research because there's tons of easier ways to do that.
I'm will try to dissect this the best I can.
First of all, I would type up an event.
1 | AnchorButton.MouseButton 1 Click:connect( function () |
Then I would need a source of text to identify the name.
Note I am going to assume that you want the full username caps sensitive and that the source of the text comes from a textbox.
1 | AnchorButton.MouseButton 1 Click:connect( function () |
2 | local text_ 1 = TextBox_ 1. Text; |
Now that I have the name, I would want to find the player with that name using Service Players's function FindFirstChild
. Your method may vary. If I find a player, it will activate the if statement scope.
1 | AnchorButton.MouseButton 1 Click:connect( function () |
2 | local text_ 1 = TextBox_ 1. Text; |
3 | local Player_ 1 = game:GetService( 'Players' ):FindFirstChild(text_ 1 ); |
Now since if I get Player_1
then they will have properties of a Player
Object. So that means I can safely index Character
with no error.
1 | AnchorButton.MouseButton 1 Click:connect( function () |
2 | local text_ 1 = TextBox_ 1. Text; |
3 | local Player_ 1 = game:GetService( 'Players' ):FindFirstChild(text_ 1 ); |
5 | local char = Player_ 1. Character; |
Now to anchor all parts in a character, I would need a table of Instances (You can use GetDescendants
on the character ) and combine it with a for loop to anchor whether its a BasePart
or not.
01 | AnchorButton.MouseButton 1 Click:connect( function () |
02 | local text_ 1 = TextBox_ 1. Text; |
03 | local Player_ 1 = game:GetService( 'Players' ):FindFirstChild(text_ 1 ); |
05 | local char = Player_ 1. Character; |
06 | local gd_ 1 = char:GetDescendants(); |
07 | for _,v in pairs (gd_ 1 ) do |
Now since not every Instance can not index Anchored
without erroring, I would need an if statement and function IsA
to check whether it's a BasePart
(not just including Part
, this also includes WedgePart
etc) or not.
01 | AnchorButton.MouseButton 1 Click:connect( function () |
02 | local text_ 1 = TextBox_ 1. Text; |
03 | local Player_ 1 = game:GetService( 'Players' ):FindFirstChild(text_ 1 ); |
05 | local char = Player_ 1. Character; |
06 | local gd_ 1 = char:GetDescendants(); |
07 | for _,v in pairs (gd_ 1 ) do |
08 | if v:IsA( 'BasePart' ) then |
And done.