How to get the highest Y position of part/model

Hi! I want to make standard pet following system and i got something bad.
When petblock find part for take is like floor, petblock in in center of part:
image|403x303 (Screenshot by Lightshot)
How to fix that? I think i need the highest Y of found floor, but idk how to get that.

1 Like

So you want the part to not go inside the part, basically the position is the center of the part, if you want the top, get half the size of the part then add it to the position

local part = workspace.Part
local partSize = part.Size -- GetExtentsSize for models
local halfSize = partSize.Y/2
part.Position = Vector3.new(part.Position.X,part.Position.Y+halfSize,part.Position.Z)

I haven’t tested this so please tell me if it doesn’t work

For models you would do something like this:

local model = workspace.Model
local Model_Size = model:GetExtentsSize() -- GetExtentsSize for models
local halfSize = Model_Size.Y/2
model:SetPrimaryPartCFrame(CFrame.new(Vector3.new(model.CFrame.p)+Vector3.new(0,halfSize,0)))
6 Likes

Get the models bounding box, then get the CFrame, then offset upwards by half of the bounding box’s Y size. Example

local myModel = modelReferenceHere
local cf, size = myModel:GetBoundingBox()

local tempCF = cf + CFrame.new(0, (Size.Y / 2), 0)
local topY = tempCF.Y
1 Like

You wouldn’t want to set the primary part cframe. All this person wants is the highest Y position of a part/model.

His model is getting stuck inside the ground because it just needs the other half of its size to bring it to the top, isn’t that what he is asking The second part of his question says he thinks he needs the highest y of the floor…