How does :GetBoundingBox() and :GetExtentsSize() work?

Hello devs, I am currently trying to achieve something like this, where a part is centred inside a model, and also completely covers the model, leaving as little excess space as possible.

Unfortunately, when I use this script (which is a child of the tree model) , I get this strange thing instead.

local model = script.Parent
local part = workspace.VulnerableHitbox
part.Parent = model
local orientation, size = model:GetBoundingBox()
part.Size = size
part.CFrame = orientation

It’s very iffy, it changes, but it usually does work slightly, where the tree is in the corner, and has as little space between it and the edge as possible, but on other parts, the part is massive for whatever reason. I’ve tried using get extents size and looking in the documentation and google, but nothing seems to work.

Any help is appreciated. Thanks!

I just realised something as well, for whatever reason, it tries to fit the model AND the parts starting position inside the box, and I’m not sure why. Could anyone help?

I also changed the parts CFrame = to be the models pivot, and that centred it, but its still way too big.

local model = script.Parent
local part = workspace.VulnerableHitbox
part.Parent = model
local orientation, size = model:GetBoundingBox()

part.CFrame = model:GetPivot()
part.Size = size

Thats the new script, and this is what it looks like in game now.

Hey there! You mentioned :GetExtentsSize() in the title, but have you actually tried attempting to use it for the “bounding box” size? You would be calling two methods, but you shouldn’t need to run them multiple times.

Sorry, i think i tried it, but i’ve found a different way around the problem, as i wanted this to be a hitbox basically, but thanks for the help!

What was your solution? I’m curious to understand what the problem was.

I actually didn’t find the problem and i’d definitely like to, i was trying to make a hitbox for multiple objects in my game, but i couldnt really be bothered to manually make one for each object. I decided to make a hitbox from the weapon and use :GetPartBoundsInBox to see the parts inside, and then i check an attribute to see whether or not i can do the following operation.