Model not rotating for some reason

local function rotateStructureInternal(structure, rotationIncreasement)
	if structure:IsA("Model") then
		structure:PivotTo(structure:GetPivot() * CFrame.Angles(0, math.rad(rotationIncreasement), 0))
	else 
		structure.CFrame = structure.CFrame * CFrame.Angles(0, math.rad(rotationIncreasement), 0)
	end
end

local function rotateStructure(structure, rotationWay)
	if rotationWay == "right" then
		while UserInputService:IsKeyDown(Enum.KeyCode.R) do
			rotateStructureInternal(structure, 1)
			task.wait(0.01)
		end
	elseif rotationWay == "left" then
		while UserInputService:IsKeyDown(Enum.KeyCode.T) do
			rotateStructureInternal(structure, -1)
			task.wait(0.01)
		end
	end
end

Full script where i call the rotateStructure function:

local function rotateStructureInternal(structure, rotationIncreasement)
	if structure:IsA("Model") then
		structure:PivotTo(structure:GetPivot() * CFrame.Angles(0, math.rad(rotationIncreasement), 0))
	else 
		structure.CFrame = structure.CFrame * CFrame.Angles(0, math.rad(rotationIncreasement), 0)
	end
end

local function rotateStructure(structure, rotationWay)
	if rotationWay == "right" then
		while UserInputService:IsKeyDown(Enum.KeyCode.R) do
			rotateStructureInternal(structure, 1)
			task.wait(0.01)
		end
	elseif rotationWay == "left" then
		while UserInputService:IsKeyDown(Enum.KeyCode.T) do
			rotateStructureInternal(structure, -1)
			task.wait(0.01)
		end
	end
end

local isPlacing = false
local function raycastStructure(structure)
	local structurePlaced = false
	local cframeToPlace

	local castingCFrameConnection = RunService.RenderStepped:Connect(function()
		local result = raycastMouseResult(structure)
		if not result then return end

		if result.Instance then
			changePlaceabilityVisuals(structure, true)
		else
			changePlaceabilityVisuals(structure, false)
		end

		cframeToPlace = CFrame.new(result.Position.X, result.Position.Y + (structure:IsA("Model") and structure:GetExtentsSize().Y / 2 or structure.Size.Y / 2), result.Position.Z)
		if structure:IsA("Model") then
			structure:PivotTo(cframeToPlace)
		else
			structure.CFrame = cframeToPlace
		end
	end)

	local placeStructureConnection = mouse.Button1Up:Connect(function()
		placeStructureEvent:InvokeServer(structure.Name, cframeToPlace)
		structurePlaced = true
	end)
	
	local rotationConnection = UserInputService.InputBegan:Connect(function(input, gameProcessed)
		if gameProcessed then return end
		
		print("Rotation triggered")
		if input.KeyCode == Enum.KeyCode.R then
			rotateStructure(structure, "right")
		elseif input.KeyCode == Enum.KeyCode.T then
			rotateStructure(structure, "left")
		end
	end)

	repeat task.wait() until structurePlaced
	buildFrame.Visible = true
	isPlacing = false
	structure:Destroy()
	castingCFrameConnection:Disconnect()
	placeStructureConnection:Disconnect()
	rotationConnection:Disconnect()
end