AssemblyRootPart doesn't exist when Character is First Loaded

I’ve been trying to get a script to add a surfboard to a player’s character as soon as their character loads in, and the code I use to do so relies on the assembly’s RootPart to do some math. However, when connecting a function to player.CharacterAdded or player.CharacterAppearanceLoaded, it seems that the AssemblyRootPart is a nil value.

For example, the following code prints “nil”:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	player.CharacterAppearanceLoaded:Connect(function(character)
		print(character.PrimaryPart.AssemblyRootPart)
	end)
end)

However, if I put a delay of say, 2 seconds:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	player.CharacterAppearanceLoaded:Connect(function(character)
                task.delay(2)
		print(character.PrimaryPart.AssemblyRootPart)
	end)
end)

Then it returns “HumanoidRootPart” as would be expected. I was wondering if there are any solutions to this issue other than putting a delay into the code, as I want the code to execute as soon as the player’s character is added. Thanks.

You could try replacing your delay with character:WaitForChild("HumanoidRootPart") or repeat task.wait() until character.PrimaryPart ~= nil. This way, your code will run as soon as HumanoidRootPart is created.

1 Like

The strange thing is that I can access the HumanoidRootPart of the player’s character. The issue is that it seemingly doesn’t recognize the player’s character (and in this case the welding of the character and surfboard) as a single assembly, so when I try to access any of the assembly properties (i.e. AssemblyMass or AssemblyRootPart), I get nil or values only representative of the part I called them on.

So are you saying that even if you get the HumanoidRootPart, the assembly properties don’t return the proper values unless you add a delay?

I just tested :WaitForChild() and found that the assembly properties don’t return the correct values for HumanoidRootPart, but using the repeat code does, although I only tested these in Studio. And while the repeat code does technically have a delay, it should run fast enough to not be noticeable. Did you try that, and if so, did it work correctly?

If the assembly properties aren’t updated fast enough for you, you could try to instead directly get the HumanoidRootPart and calculate the assembly mass yourself (it’s basically the sum of every part’s mass in the character except accessories it seems). The AssemblyRootPart for every part in the character should be the HumanoidRootPart.

I apologize if I’m not understanding or sufficiently solving your problem. I haven’t noticed these assembly properties until I came across your post so they’re pretty new to me.

That’s alright, I appreciate your responses. The Assembly properties are really useful when they work. To clarify, you don’t need to get the HRP to access assembly properties, you just need one instance that is a part of that assembly (for more clarification, Roblox has a nice intro article here: Understanding Assemblies | Roblox Creator Documentation). I guess I can try the repeat code but I would prefer to try and find another way around this problem.

1 Like