Need help with scripting dragging for a building tool

If you want the part to maintain it’s original orientation, you need to add the angles of it to your new CFrame.

local angle = Part.CFrame - Part.Position
while Dragging do -- don't need to compare to true, this is checks if it's true by default.
	wait()
	if ObjBeingDragged ~= nil and Mouse.Target ~= nil and Mouse.Target ~= ObjBeingDragged then
		Part.Anchored = true
		ObjBeingDragged.CanCollide = false
		Part.CFrame = angle + Vector3.new(filter(Mouse.Hit.X,Increment),Mouse.Hit.Y + (Part.Size.Y/2),filter(Mouse.Hit.Z,Increment))
	end
end

I you want to be able to rotate it, just change the CFrame line to add a rotation and then add 90 degress (or degrees of your choice) every time the player presses R. You can do the same thing for tilting by adding to X or Z.;

local CAS = game:GetService'ContextActionService' -- probably most efficient if this line is in the outermost scope at the top of the script.
local angle = Part.CFrame - Part.Position
local rotation = Vector3.new(0, 0, 0)
local rotate = function()
    rotation = rotation + Vector3.new(0, -90, 0) -- negative is clockwise, positive is counterclockwise
end
CAS :BindAction('Rotate Action', rotate, true, Enum.KeyCode.R) -- true means there will be a mobile button added for this too, which will automatically work the same as pressing R while moving a part.
while Dragging do
	wait()
	if ObjBeingDragged ~= nil and Mouse.Target ~= nil and Mouse.Target ~= ObjBeingDragged then
		Part.Anchored = true
		ObjBeingDragged.CanCollide = false
		Part.CFrame = (angle + Vector3.new(filter(Mouse.Hit.X,Increment),Mouse.Hit.Y + (Part.Size.Y/2),filter(Mouse.Hit.Z,Increment))) * CFrame.Angles(math.rad(rotation.X), math.rad(rotation.Y), math.rad(rotation.Z)) -- if you add tilt to the rotation function, this cframe line will already work for your needs.
	end
end
CAS :UnbindAction('Rotate Action')

As for placing on “walls”, you can use Mouse.TargetSurface to see what side of the part that the mouse.Hit is touching.

You will then need to add the relative x or z difference in studs from the center of the part (width/2) that you are moving from the current mouse.Hit, relative to the part your mouse is on. This part is a little complicated, and I thought I saw that the link I sent before also showed snapping to walls? Is that what you want?

I think he makes the bottom face of the part snap to the wall, you can edit that part to use the face that is facing the wall.

for the rotation, i have to hold down the R key, meaning that i cannot rotate more than once, and when i place down the part, it just resets back to its original orientation. And i also can’t seem to get the surface detector thingy to work.

Forgot to mention this, but by maintaining the orientation, i meant keep the orientation to right angles on the objects that i place onto, so they can also join onto surfaces. And i just realized that i cannot put parts onto slightly moved, or rotated objects, which will not allow the part to join surfaces, and line up with the object that the part is on