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.
AnchorButton.MouseButton1Click:connect(function()
end)
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.
AnchorButton.MouseButton1Click:connect(function()
local text_1 = TextBox_1.Text;
end)
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.
AnchorButton.MouseButton1Click:connect(function()
local text_1 = TextBox_1.Text;
local Player_1 = game:GetService('Players'):FindFirstChild(text_1);
if Player_1 then
end;
end)
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.
AnchorButton.MouseButton1Click:connect(function()
local text_1 = TextBox_1.Text;
local Player_1 = game:GetService('Players'):FindFirstChild(text_1);
if Player_1 then
local char=Player_1.Character;
end;
end)
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.
AnchorButton.MouseButton1Click:connect(function()
local text_1 = TextBox_1.Text;
local Player_1 = game:GetService('Players'):FindFirstChild(text_1);
if Player_1 then
local char=Player_1.Character;
local gd_1=char:GetDescendants();
for _,v in pairs(gd_1)do
end;
end;
end)
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.
AnchorButton.MouseButton1Click:connect(function()
local text_1 = TextBox_1.Text;
local Player_1 = game:GetService('Players'):FindFirstChild(text_1);
if Player_1 then
local char=Player_1.Character;
local gd_1=char:GetDescendants();
for _,v in pairs(gd_1)do
if v:IsA('BasePart')then
v.Anchored=true;
end;
end;
end;
end)
And done.
3 comments
You could do: "game.players[game.Players.AnchorPlayer.Text].Character.Head.Anchored = true"
... "AnchorPlayer.text.Character"?
@Benbebop it does not work "game.Players[game.Players.AnchorPlayer1.Text].Character.Head.Anchored = true"