toObjectSpace issue

I am trying to find the position of an object around a part rather than the world (0,0,0) hence why I am using toObjectSpace.

To perform this task, I have made 2 parts and I am creating a new part which I am trying to position on point B.

–The Script:
local A = workspace.A --Green Part (Origin)
local B = workspace.B --Pink Part
local origin = B.CFrame:toObjectSpace(A.CFrame)
local part = Instance.new(“Part”, workspace) --Grey Part
part.Anchored = true
part.Size = B.Size
part.CFrame = origin + Vector3.new(part.Position)

In this picture, the green part is my new origin, whilst the pink part is where I want my new part to go on.

The new part (grey) is not going where I want it to go :disappointed_relieved:

local A = workspace.A --Green Part (Origin)
local B = workspace.B --Pink Part
local origin = A.CFrame:toObjectSpace(B.CFrame)
local part = Instance.new("Part", workspace) --Grey Part
part.Anchored = true
part.Size = B.Size
part.CFrame = A.CFrame * origin

Is this what you’re trying to achieve? You want the offset from A to B, you switched those around. Also I’m not entirely sure why you make a new Vector3 from a Vector3 value (a position)

Note that CFrame * someotherCFrame is equivalent to CFrame:toWorldSpace, which is more in line to your initial approach

2 Likes

Thanks!