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

How do i anchor specific people using a GUI? (Im a beginner)

Asked by
imaA6D 39
4 years ago

I need help i am beginner scripter and sorry for bad English i just want it so when i put player name in text box like type their name in the box and press a button to anchor them

AnchorButton.MouseButton1Click:connect(function() game.Players.AnchorPlayer1.Text.Character.Head.Anchored = true game.Players.AnchorPlayer2.Text.Character.Head.Anchored = true game.Players.AnchorPlayer3.Text.Character.Head.Anchored = true game.Players.AnchorPlayer4.Text.Character.Head.Anchored = true game.Players.AnchorPlayer5.Text.Character.Head.Anchored = true game.Players.AnchorPlayer6.Text.Character.Head.Anchored = true end)

0
You could do: "game.players[game.Players.AnchorPlayer.Text].Character.Head.Anchored = true" Benbebop 1049 — 4y
0
... "AnchorPlayer.text.Character"? speedyfox66 237 — 4y
0
@Benbebop it does not work "game.Players[game.Players.AnchorPlayer1.Text].Character.Head.Anchored = true" imaA6D 39 — 4y

1 answer

Log in to vote
2
Answered by 4 years ago

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() -- I'll use your's.

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() -- I'll use your's.
    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() -- I'll use your's.
    local text_1 = TextBox_1.Text;
    local Player_1 = game:GetService('Players'):FindFirstChild(text_1);
    if Player_1 then -- checks if then value of variable Player_1 exists 

    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() -- I'll use your's.
    local text_1 = TextBox_1.Text;
    local Player_1 = game:GetService('Players'):FindFirstChild(text_1);
    if Player_1 then -- checks if then value of variable Player_1 exists 
        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() -- I'll use your's.
    local text_1 = TextBox_1.Text;
    local Player_1 = game:GetService('Players'):FindFirstChild(text_1);
    if Player_1 then -- checks if then value of variable Player_1 exists 
        local char=Player_1.Character;
        local gd_1=char:GetDescendants();
        for _,v in pairs(gd_1)do -- note since GetDescendants returns an array, in this case, indexes from this table are unnecessary

        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() -- I'll use your's.
    local text_1 = TextBox_1.Text;
    local Player_1 = game:GetService('Players'):FindFirstChild(text_1);
    if Player_1 then -- checks if then value of variable Player_1 exists 
        local char=Player_1.Character;
        local gd_1=char:GetDescendants();
        for _,v in pairs(gd_1)do -- note since GetDescendants returns an array, in this case, indexes from this table are unnecessary
            if v:IsA('BasePart')then
                v.Anchored=true;
            end;
        end;
    end;
end)

And done.

Ad

Answer this question