Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

3 comments

0

This should work, if it doesn't let me know so I can fix it for you.

0

Thank you so much!

0

No problemo.

This discussion is preserved as it was. New answers, comments, and votes are closed.