Best/performant way to get root of character?

I was working on a system for my game, basically combat, and got to adding the variable to get the rootpart of the character like so:

local player = playerthingblah -- not important for this discussion, I think
local character = player.Character -- can also have wait if on client
local rootpart = character:WaitForChild("HumanoidRootPart")

As I was looking over the code, I began to wonder if it was actually the “recommended” way (if there even is one) of getting the rootpart of the character? (I actually never really bothered trying to find out if there was one since I didn’t think too much of it)

I looked around at how others got some characters and I found a few different examples:

local humanoid = character:WaitForChild("Humanoid")
local rootpart = humanoid.RootPart -- gets rootpart from humanoid instance

and

local character = player.Character
local rootpart = character.PrimaryPart -- gets rootpart from primarypart of model

I remember there being other examples as well but thats the only ones I can remember finding off the top of my head.

I don’t think it matters much, and I would go for the first option with the WaitForChild(“HumanoidRootPart”) method because it’s simple and fast.

All Methods are Valid, It doesnt really matter on what you choose.

The fastest ones are the ones that are already referenced (Character.PrimaryPart and Humanoid.RootPart) as you basically have direct access to it, and you dont exactly need to reference it in a Variable as its already referenced in a Property, however, Assiging objects in a Variable is usually faster for about the same reason.

WaitForChild isnt fast, its speed can vary.

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