Pls Help with part

local part = Instance.new("Part")
part.Name = "prat"
part.Parent = workspace
part.Anchored = true

game.Players.PlayerAdded:Connect(function(plr)
	local char = plr.Character.HumanoidRootPart
	part.CFrame = char.CFrame
	end)

I need the part to appear under the player and follow him but I can’t figure out how it works. As far as I understand, I don’t need the playeradded function.
image
I also can’t figure out why the error occurs.

1 Like

it takes a while for the character and the humanoidrootpart to load in so try using

plr.CharacterAdded:Connect(function(char)
local HRP = char.HumanoidRootPart
end)

also this doesn’t achieve your final goal you should use welds for that

1 Like
local part = Instance.new("Part")
part.Name = "prat"
part.Parent = workspace
part.Anchored = true

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(character)
        local char = character:FindFirstChild("HumanoidRootPart")
	part.CFrame = char.CFrame
	end)
end)
1 Like

I don’t recommend you to use “FindFirstChild()” here as it can return “nil” if it can’t find the humanoidrootpart, go for “WaitForChild()” instead.

1 Like

CharacterAdded event is fired when players character spawns meaning they will have HumanoidRootPart

Yup! but if he is trying to achieve this from a local script it can actually take a few miliseconds before the client recognizes the humanoidrootpart inside the character.

Why would you use PlayerAdded in a local script when you can just do game.Players.LocalPlayer?

image
the part appears but not in the humanoidrootpart I think if i change its parent to something other than workspace, it will appear in the player?

You never know, OP seems like a newbie so expect everything

No first of all disable CanCollide property of the part, then create a WeldConstraint and weld the part to the humrp

I feel like beginner would be a more friendly word than newbie, just saying.

newbie, newcomer, fledgling, fledgeling, starter, neophyte, freshman, entrant, beginner, initiate, novice, tiro, tyro; all has the same meaning :slight_smile:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.