How do I move items relative to the closet? (CFrame)

This might be a stupid question, I’m not good at CFrames.
For example, let’s say I have a closet. It’s orientation is (0,90,0). Moving items between upper and lower shelves is easy, you just change the Y coordinate.
Moving items to the side is also easy, as long as the closet’s orientation and position stays the same. Otherwise the item will be moved outside the closet.
How do I make it so that items are moved relative to the closet’s PrimaryPart, instead of the World?
The closet’s position is (122.938, 3.857, -91.938). Currently I’m using absolute positions to move the items, which are:

--Z axis
Item1 =  -91.277 
Item2 = -91.688
Item3 = -92.17
Item4 = -92.58
--Y axis
Shelf1 = 2.62
Shelf2 = 3.96
Shelf3 = 4.41

--X axis is 123.207 in all cases, btw

I want to make them relative to the PrimaryPart.

I believe:

local ItemCFrame = CFrame.new(Vector3.new(0,1,0))-- Where it will be placed

Item.CFrame = ItemCFrame:ToObjectSpace(Closet.PrimaryPart.CFrame)
2 Likes

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