Spawning parts in rotated part

So I’ve been working on a boss fight and been wanting to add a little more detail. I’m trying to spawn smaller parts inside his laser beam attacks. I’m having some problems in testing though.
It seems whenever the main part is rotated the other parts do not follow the rotation.
Here is the code and I’m kind of clueless on how to fix this.

local PartToSpawnPartsIn = script.Parent

local PartClonable = game.ReplicatedStorage.Part

for i = 1, 100 do
local PartClone = PartClonable:Clone()
PartClone.Position = PartToSpawnPartsIn.Position
local ThingToDo = PartClonable.Size.X/2
local ThingToDo2 = PartClonable.Size.Z/2
local MaxX = (PartToSpawnPartsIn.Size.X/2)-ThingToDo
local MinX = (PartToSpawnPartsIn.Size.X/2)-((PartToSpawnPartsIn.Size.X/2)*2)+ThingToDo
local RandomX = (math.random(MinX,MaxX))
local MaxZ = (PartToSpawnPartsIn.Size.Z/2)-ThingToDo2
local MinZ = (PartToSpawnPartsIn.Size.Z/2)-((PartToSpawnPartsIn.Size.Z/2)*2)+ThingToDo2
local RandomZ = (math.random(MinZ,MaxZ))
PartClone.Position = PartClone.Position +,0,RandomZ)
PartClone.Parent = workspace

1 Like

Which one of those variables is the main, longer part? Your variable names are hard to understand.


That didn’t answer my question. So let me take a guess instead. Is the variable the parts should be spawning along the rotation of Part?

Here I redid the variable names.

I think you should try using CFrame instead of positioning, as setting the part’s CFrame will automatically rotate it to the rotation of the block you’re spawning it on

1 Like

Use this, account for rotation.

PartClone.Position = (PartToSpawnPartsIn.CFrame *,0,-RandomZ)).p

This is a pretty nice resource for things like this.
Edit oops read your post wrong…