How do I place a part directly in front of another part? (Parts of different sizes)

I am trying to make a rainbow platform composed of many different parts with different sizes.

The issue is that I am unsure of how to calculate the sizes/positions of the parts to position the next part to be in front of the last part. I tried the following code, but it only works if the parts are of the same size:

local Part = game.Workspace.Worlds.Overworld.ImportantParts.StudParts["Start"]

local Start = game.Workspace.Worlds.Overworld.ImportantParts.StudStart

Part.Position = Start.Position - Vector3.new(0,0,Part.Size.X/2)

I have searched 25+ dev forum posts and even tried the Roblox Assistant, but I have not found any luck with these resources. I may be overlooking it, but any guidance on this issue of mine is greatly appreciated.

1 Like

You should calculate the offset based on the size of each part and subtract it from the position of the previous part to position the next part in front

Edit: try making a variable where you want to stack the parts (you use z axys)

local Part = game.Workspace.Worlds.Overworld.ImportantParts.StudParts["Start"]
local Start = game.Workspace.Worlds.Overworld.ImportantParts.StudStart

local offset = Vector3.new(0, 0, Part.Size.X / 2) -- here you stack the parts along the z-axis
local newPosition = Start.Position - offset

Part.Position = newPosition

This is just an example based on yours

1 Like

I have attempted this all day, do you mind sending me a code example?

1 Like

I tried your example, and it does not work as I need. Part1 should not overlap with part2. It seems it is positioning the parts based on the pivot point. (Which is not what I need)

image

1 Like

Then adjust the positioning accordingly.

Instead of this

local offset = Vector3.new(0, 0, Part.Size.X / 2) -- here you stack the parts along the z-axis

Replace it in this variable so they dont overlap, here you check widths of both parts

local offset = Vector3.new(0, 0, Part1.Size.X / 2 + Part2.Size.X / 2) -- offset by the combined widths of both parts

Edit: forget to tell you about making a variable for the other part

1 Like

That worked! Thank you for your help with my issue, as I am not the best at calculating positions. Have a blessed day!

1 Like

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