I’ve been working on making a part that could be instanced into the player’s model in the workspace. The problem is in my output, it seems that it is always assigning nil to the HRP. I’ve tried looking at several videos and documentations but my script never worked.
game.Players.PlayerAdded:Connect(function(player)
local part = Instance.new("Part")
local chr = player
local HRP = chr:FindFirstChild("HumanoidRootPart")
print("yes")
local newPart = part:Clone()
newPart.Parent = chr
newPart.Position = HRP.Position + Vector3.new(0,-3,0)
end)
The player doesnt have a root part. That would be the character.
Try this:
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(chr)
local part = Instance.new("Part")
local chr = player
local HRP = chr:FindFirstChild("HumanoidRootPart")
print("yes")
local newPart = part:Clone()
newPart.Parent = chr
newPart.Position = HRP.Position + Vector3.new(0,-3,0)
end)
end)
This way, Your character will always have the part when they spawn in.
Also, A little note about this, The player is an object inside the Players service, While characters are assigned to players, And spawn in the workspace.