How can I fix this?

Well, the issue is storing the placement data. You could have stored the data on if a part has a block placed or not. However, it might be too much data to use a table or values for.

That’s not my problem, I have a folder called “PlacedBlocks” and whenever a block is placed it gets stored there. I am trying to detect if a block is inside another block.

If two blocks have an equivalent Vector3 position then you know if it’s inside or not.

Yep, that’s what I did but I don’t know what to do next. I have to move the block out of the way but the direction is important.

Alternatively you can just cancel the placement.
That would be too easy, however, so just check where the player / camera is located and place the block to the direction of the player / camera.

How would I do that? Would I check to see which face of the block is closest to the camera?

Well, I’d say you can do so, and I don’t really have anything else to think of in this situation.

You can use a .Touched event or part:GetTouchingParts() to check if something is colliding with another object.

Yes but how would that help with my solution?

I found out an approach using This Post. It uses attachments to snap a block in place.

I tried the method but it kept on moving like this. Can someone help me fix this?
Here’s some code:

local ClosestDistance = 10
local Closest
ocal targ = mouse.Target.Parent.PrimaryPart
local PosTable = {targ.Position + Vector3.new(targ.Size.X, 0, 0), targ.Position - Vector3.new(targ.Size.X, 0, 0), targ.Position + Vector3.new(0, 0, targ.Size.Y), targ.Position - Vector3.new(0, 0, targ.Size.Y)}
for i, v in pairs(PosTable) do
        local mousePos = mouse.Hit.p
	local distance = (mousePos - v).Magnitude
	if distance < ClosestDistance then
		ClosestDistance = distance
		Closest = v
	end
end						
block.PrimaryPart.Position = Closest
return

Here’s a video:

I’m not adding onto any position or cframe so I don’t know what the problem is.

Have you tried using IsRegion3Empty to detect if the part intersected with another?

EDIT

I would recommend when the mouse moves with the block (assuming you’re using Mouse.Move).

Ok I’ll look into that. Where would I put a region3 though?

1 Like

I have a script that checks if any other block has the same position and then alerts to move the block somewhere else.

Now that I think of it, I am using RunService.RenderStepped. I’ll change it to mouse.Move.

1 Like

Ok thanks for that tip, the block still doesn’t move 4 studs(The grid size) but it moves not far away.

it says “ocal” i dont know if you somehow didnt fit that part of the code in but that code be it??

Oops. In the real code it said local it just got cut off.

1 Like

Here’s what I got done. The block doesn’t move with the mouse though: