Retreiving Sides Position

Hello Devs!

I’ve been having a tiny problem with getting the Left and Right Positions of a Part, to place another Part. I’ve already got the Top and Bottom

-- Top
AddedPart.CFrame = Target.CFrame + Vector3.new(0, Target.Size.Y/2 + AddedPart.Size.Y/2, 0)
-- Bottom
AddedPart.CFrame = Target.CFrame + Vector3.new(0, -Target.Size.Y/2 - AddedPart.Size.Y/2, 0)

I’ve tried to do the Right side but it doesn’t seem to move at all.

-- Right
AddedPart.CFrame = Target.CFrame + Vector3.new(-Target.Size.X/2 + AddedPart.Size.X/2, 0, 0)

Sorry if this is a easy question, practicing object oriented scripting!

CFrame multiplication is basically just applying relative positions

part.CFrame * CFrame.new(leftRight,0,0) gets the left and right offsets relative to the part
part.CFrame * CFrame.new(0,upDown,0) gets the up and down offsets relative to the part
part.CFrame * CFrame.new(0,0,frontBack) gets the front and back offsets relative to the part

These can all be combined to do some pretty useful things
So basically all you need to do is do * CFrame.new( instead of + Vector3.new(

Oh okay, thank you for the info!

I tried doing it with CFrame multiplication, It worked with top and bottom again, but not the other sides like Right

-- CFrame Multiplication | Right Side
AddedPart.CFrame = AddedPart.CFrame * CFrame.new(Target.Size.X/2 + AddedPart.Size.X/2,0,0)

Unless I am doing it wrong, I probably am :sweat:

I think its just that you accidentally put AddedPart on the second part instead of Target
Like:

AddedPart.CFrame = Target.CFrame * CFrame.new(Target.Size.X/2 + AddedPart.Size.X/2,0,0)

Hmm, I have no Idea of how I missed that, but It still doesn’t work, It just stays at original Parts CFrame.

The added part doesnt move at all? Or does the added part go to the target but not the right position

It goes to the target but not the right position.

Does it go to the front? Left? etc
If so it would just be as simple as changing around the values a bit until it works

It doesn’t go either, It goes to the original target’s CFrame

Have you tried using the Z size instead or made other small changes which might affect it?
You could even try putting a set value in the cframe to see if its properly responding to a value
Eg:

AddedPart.CFrame = Target.CFrame * CFrame.new(10,0,0)

I just tested it and it worked! but It doesn’t work on that line

	if selection == Target then
		if side == "Top" then
			AddedPart.CFrame = Target.CFrame * CFrame.new(0, Target.Size.Y/2 + AddedPart.Size.Y/2, 0)
		elseif side == "Bottom" then			
			AddedPart.CFrame = Target.CFrame * CFrame.new(0, -Target.Size.Y/2 - AddedPart.Size.Y/2, 0)
		elseif side == "Right" then -- Doesn't work here
			AddedPart.CFrame = Target.CFrame * CFrame.new(Target.Size.X/2 + AddedPart.Size.X/2,0,0)	 -- Works Perfectly
		end
	end
	

Wow, not sure why but the problem wasn’t the placement but it was the if statement. Didn’t know it couldn’t hold more than 3 elseif. Thank you for your help!