How to make a loop that keeps adding parts around and facing towards point until it's 360?

I made a script that creates 18 parts around another part, but I can’t make the part’s bottom keep facing the axis part, heres my script:

currentangle = 0
Offset = CFrame.new(0,0,7)
repeat
local p = Instance.new("Part")
p.CFrame = script.Parent.CFrame * CFrame.Angles(0,math.rad(currentangle),0) * Offset
p.Orientation = Vector3.new(0,0,0)
p.Anchored = true
p.Size = Vector3.new(2,7,4)
p.Parent = script.Parent
currentangle = currentangle + 20
until currentangle == 360

Basically it creates a loop that keeps making a part rotate around the axis part and keeps adding 20
to the variable that defines how much it should rotate each loop until it gets to 360 to stop.
However I could not figure out a way to make the bottom point towards the axis part, here’s a demonstration of what i want it to do:

I saw another Topic probably like this, but I could not understand a single word they said,
any help would be very appreciated.

1 Like

Well you can utilise lookVectors which are (really simply) the looking direction of a part.

p.CFrame = script.Parent.CFrame * CFrame.Angles(0,math.rad(currentangle),0) * Offset

But here you are setting the new part’s cframe to script.Parent.CFrame which might actually make it face torwards the original part, if script.Parent is actually the original part.
But simply

part1.CFrame = CFrame.new(2,2,2, part2.Position)

So you see in cframe, the first 3 paramaters, or the first vector is the position, and the 2nd vector, which here is part2.Position is actually setting where the part is gonna look, we set it to the position of part2 so it is gonna be place at 2,2,2 and will face part2.

But I might be wrong because if script.Parent is actually the original part, and you are indeed setting it direction, because doing

part.CFrame = script.Parent.CFrame
--is littearly the same as
part.CFrame = CFrame.new(script.Parent.Position, script.Parent.Position)
--and i think that this line would error I think because you 
--can't set a part's cframe to the same position and same direction

https://gyazo.com/868762059bee778d80fc360d27c25a41.png

And yeah this should work

1 Like

No, they’re not the same. Using CFrame.new(position, look) makes a CFrame at the position with its LookVector pointing at look. Having something look at itself is not the same as preserving something’s rotation.

Also, in your second code sample, you’re not constructing a Vector properly. You would have to do Vector3.new(2,2,2) instead of just 2,2,2.

1 Like

Yeah really sorry about that mistake