# How to make part go on top of anotherother part?

Hello everyone! I’m hoping to be able to put a part on top, in the middle of another part. Can that be done?
I’m getting a clone out of the serverstorage, and want to put that on top of another part.

1 Like

You can use Model:MoveTo(). This will put the model (focusing on the PrimaryPart) on top of the position you give it.

Isn’t there a way to make the bottom of a part touch the top of another (specified) part and put it there? I already know how to change the position of a part.

MoveTo will attempt to place the model at the given position, but will move up until there is no more collision. This is all done at once. If this is not the answer you’re looking for, you’ll have to explain in more detail.

That seems like a good solution, Ill look into it.

The top position can be calculated using the following formula: `FloorPosY+FloorSizeY/2+PartSizeY/2`

``````local Floor = workspace.Baseplate
local Part = workspace.Part

local Y = Floor.Position.Y+Floor.Size.Y/2+Part.Size.Y/2
Part.Position = Vector3.new(Floor.Position.X, Y, Floor.Position.Z)
``````
2 Likes

Get the Y Position of the bottom Part.
Get half it’s height (bottom y/2).
Get half of the top Part’s height (top y/2).
Add the three together Y + (bottom y/2) + (top y/2) = the Y position of the top Part.

How do I get the position of the model/part I want to go to and tell my part to go there?

This is not ideal as it does not take anything else into account, such as orientation or if it’s a model instead of a single rectangular part.

If using another method aside from `MoveTo`, which I believe is the desired method in this case, it would be better to replicate the operation that `MoveTo` uses. You’d do this by moving the part or model to the given position and moving it upward until none of its parts collide. But I don’t see the point to doing this if `MoveTo` does this more efficiently.

1 Like

That’s correct, this method only applies to simple geometrical shapes that aren’t rotated on the Y axis, it can be used for simple systems like item placing and drawing, although for more complicated systems(such as an in-game build system with a lot of configurations) it’s better to use `MoveTo`.

1 Like

I have now got this:

``````local Part = game.ServerStorage.Part:Clone()
Part.Parent = workspace
local TableLocation = workspace.table.TPPart.Position
print(TableLocation)
workspace.Part.Position = TableLocation

wait (10)
Part:Destroy()
``````

How do I use Model:MoveTo with this?

`MoveTo` is a function exclusive to the `Model` class (not to be confused with the humanoid move functions).

You’ll need to create a model, parent the part to that model, make that part the PrimaryPart of said model, use the `MoveTo` function on the model, then you can re-parent the part out of the model and destroy it.

Edit:
Also, you should be using `task.wait()` now.

How would that look like in my script? I’m quite new to scripting.
I made this, but it only does the same thing it did before, it doesn’t go on top of the table, only inside.

``````local Model = game.ServerStorage.Model:Clone()
Model.Parent = workspace
local TableLocation = workspace.table.TPPart.Position
print(TableLocation)
workspace.Model.Part.Position = TableLocation
local endPosition = TableLocation
Model.MoveTo(endPosition)
``````

(In serverstorage there is now a model with a part inside)

``````local tableLocation = workspace:WaitForChild('Table'):WaitForChild('TPPart').Position
local model = game:GetService('ServerStorage'):WaitForChild('Model')
model.PrimayPart = model:WaitForChild('Part')
local clone = model:Clone()
clone.Parent = workspace
clone:MoveTo(tableLocation)
``````

That did not work for some reason

Edit: nevermind. Primarypart was primaypart on accident.

Thank you!

1 Like