I try to make a dungeon generator
function GenerateRoom(position,rotation)
if roomsNumber >= roomsNumberMax then return end
local whichRoom = RoomsNames[math.random(1,#RoomsNames)]
local room = whichRoom:Clone()
room.Parent = game.Workspace.Facility
local attachment = room.PrimaryPart:FindFirstChildWhichIsA("Attachment")
if attachment then
room:PivotTo(CFrame.new(position + attachment.Position))
local CFRot1 = CFrame.lookAt(room.PrimaryPart.Position,attachment.WorldPosition)
local CFRot = CFrame.lookAt(attachment.WorldPosition,position)
room:PivotTo(CFrame.new(position + attachment.Position)*CFrame.fromEulerAnglesXYZ(CFRot:ToEulerAnglesXYZ()))
attachment:Destroy()
end
I know that this is messy but i tried a lot of things and this how i ended up. It doesnt work rotation is bad and position