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.
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
eko33550
(eko33550)
July 10, 2024, 11:44am
#3
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
bura1414
(Bura)
July 10, 2024, 11:46am
#5
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.
eko33550
(eko33550)
July 10, 2024, 11:48am
#7
Why would you use PlayerAdded in a local script when you can just do game.Players.LocalPlayer?
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
eko33550
(eko33550)
July 10, 2024, 11:55am
#11
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
1 Like
system
(system)
Closed
July 24, 2024, 11:56am
#13
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.