Cant get a building system right

Never tried to make a building system but now im trying to. This is the closest i got, but the objects move via the center of he part/model. I tried fixing this with detecting the face the mouse was hitting, but that stops working when rotation is involved.


local Snap = 0.5
local Camera = game.Workspace.CurrentCamera
local Mouse = game.Players.LocalPlayer:GetMouse()

local Dragging = false
local DragObj = nil

local Snap = 0.25

local Hovering = nil


local function SnapToGrid(position)
	return Vector3.new(math.floor(position.X/Snap) * Snap, math.floor(position.Y/Snap) * Snap, math.floor(position.Z/Snap) * Snap)
end

local function Drag(ObjModel : Other)
	Dragging = true
	DragObj = ObjModel

	task.spawn(function()
		if ObjModel:IsA("Model") then
			
			for _, V in ObjModel:GetDescendants() do
				if V:IsA("BasePart") then
					V.Transparency = 0.7
					V.CanCollide = false
				end
			end
			
			while Dragging == true do
				Mouse.TargetFilter = ObjModel

				local Pos = SnapToGrid(Mouse.Hit.Position)
				

				ObjModel:PivotTo(CFrame.new(Pos))
				task.wait()
			end
		else
			
			ObjModel.Transparency = 0.7
			
			while Dragging == true do
				Mouse.TargetFilter = ObjModel

				local Pos = SnapToGrid(Mouse.Hit.Position)
				

				ObjModel.Position = Pos
				task.wait()
			end
		end
	end)
end


-------------------EVERYTHING AFTER THIS IS JUST FOR TESTING, AND IS NOT FINAL---------------------------------------------

task.wait(1)
Drag(game.Workspace.WoodBlock) --Initalize drag

game.UserInputService.InputBegan:Connect(function(KC) --Placement test
	if KC.KeyCode == Enum.KeyCode.E then
		if DragObj:IsA("Model") then
			game.ReplicatedStorage.PlaceObject:FireServer(DragObj:GetPivot(), DragObj.Name)
		else
			game.ReplicatedStorage.PlaceObject:FireServer(DragObj.CFrame, DragObj.Name)
		end
	end
end)

Please help

Also i know im getting useless variables at the top, forgot to remove those from previous tests

can you show me video of example pelase? i didn’t understand yet

1 Like

Hi just tuning in here temporarily, so what are you trying to achieve? Are you trying to make a global snap to grid or are you trying to have which ever face its closest to it doesn’t collide?

Example this house with red objects they snap along the plane they’re connected to?

Yes, i want it to snap along the plane its touching. Not go inside it. Ive been trying to figure his out for hours. Building systems are new to me

If I understand this then you might need to offset the model or maybe edit the objects pivot point. Maybe try changing

To something along the lines of this:

local Offset = ObjModel.Size.Y / 2
ObjModel:PivotTo(CFrame.new(Pos.X, Pos.Y + OffsetY, Pos.Z))