Problem with CFrame and orientation

Hi, Im making a roblox game, i want so it makes a line of blocks that then it rotates if i enter 90 then it rotate 90 degrees, but it still goes forward, it does rotate tho here is a picture of the block rotation


here is the code:

local num1 = 10
local BlocksX = {}
local lastBlock = nil
local lastModel = nil

local cooldowntable = {}
local function cloneBlock(pos, XorY, color, rotation,parent)
	local block = game.ServerStorage.Block:Clone()
	block.Parent = workspace
	block.Anchored = true
	block.BrickColor = color
	if parent then
		block.Parent = parent
	end
	block.CFrame = pos
	 print(block:GetPivot())
	lastBlock = block
	if XorY == "x" then
		table.insert(BlocksX, block)
	else
		table.insert(BlocksY, block)
	end
end



local function createWall(plr,rotateOffset,dependOnPlayer,doRotate)
	local sum = 0
	local pos
	if doRotate == false then
		local newPos = Vector3.new(3,0,0)
		pos = plr.Character.HumanoidRootPart.CFrame
		pos = pos + newPos
	else
		local newPos = Vector3.new(0,0,-3)
		pos = lastBlock.CFrame * CFrame.fromEulerAnglesXYZ(math.rad(rotateOffset),math.rad(-rotateOffset*2),0) + newPos
		
	end
	
		for i = 0,num1,1 do
			 cloneBlock(pos + Vector3.new(sum,0,0),"x",BrickColor.random(),rotateOffset)
			sum += 3
			wait(.01)
		end
	
end



	



game.ReplicatedStorage.FireServer.OnServerEvent:Connect(function(plr)
	print("server")
	if table.find(cooldowntable,plr) then return end
	task.spawn(function()
		table.insert(cooldowntable,plr)
		wait(1)
		for i, v in game.Players:GetPlayers() do
			if table.find(cooldowntable,plr) then
				table.remove(cooldowntable,i)
			end
		end
	end)
	
	createWall(plr,0,true,false)
	createWall(plr,90,false,true)
end)

All help appreciated, Thanks :smiley:
Edit: I want it to all sides 180 270 360, ty!

theres numerous things wrong with the provided code but uhh, basically position when changed doesnt care about rotation; you probably want do to something like

-- just declaring types for clarity of this code block
local Part:BasePart
local StartingPosition:Vector3
local RotationCFrame:CFrame
local displacement:number
-- setting the cooridnate frame of the part
Part.CFrame = CFrame.new(StartingPosition)*RotationCFrame*CFrame.new(0, 0, -displacement)
--[[ 
The above code creates a new CFrame at `StartingPosition`, 
rotates it based on `RotationCFrame` (which will probably be a CFrame created with CFrame.Angles), 
and then moves it forward by amount `displacement`
]]

there are plenty of CFrame tutorials out there for you to lookup if things don’t make sense here