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

Can anyone help with an anchoring a specific persons head function thing? (Please help im beginner)

Asked by
imaA6D 39
4 years ago

Hey, im making GUI in my studio and i added an textbox and textbutton to the GUI. Im trying to make it so when i put a players name in the "textbox" and press the "textbutton" i would anchor the HEAD and not whole BODY. (im a beginner at scripting and sorry for bad english)

TButton.MouseButton1Click:connect(function()
    local text_1 = AnchorP1.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)

1 answer

Log in to vote
0
Answered by 4 years ago

Here you go. Cleaned it up a bit for you.

All that happened is you forgot to do some stuff in the script.

TButton.MouseButton1Click:Connect(function()
    local plrText = AnchorP1
    local player = game:GetService("Players"):FindFirstChild(plrText.Text)

    if player then
        local char = player.Character or player.CharacterAdded:Wait()
        if char then
            for _,part in pairs(char:GetChildren()) do
                if part.Name == "Head" then
                    part.Anchored = true
                end
            end
        end
    end
end)
0
This should work, if it doesn't let me know so I can fix it for you. killerbrenden 1537 — 4y
0
Thank you so much! imaA6D 39 — 4y
0
No problemo. killerbrenden 1537 — 4y
Ad

Answer this question