Placement system is only placing on one side of a part

So I was trying to make a placement system with a grid and It kind of worked but I have this problem;

I can only place blocks on a certain side of other blocks.
I can’t really explain it but this is what I mean:

So the black square is the block that has already been placed, the green squares is the place where I can place blocks, but the red is where I cannot place blocks.

I don’t want this to happen.

Here is the script(It is all done on client side):

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

local Tool = script.Parent
local ToolEquiped = false

function round(number, to)
	return math.floor((number / to) + 0.5) * to

local TestPart ="Part")
TestPart.Parent = workspace
TestPart.Size =,5,5)
TestPart.BrickColor ="Institutional white")
TestPart.Transparency = 0.5
TestPart.CanCollide = false
TestPart.Anchored = true

Mouse.TargetFilter = TestPart

	ToolEquiped = true
	while ToolEquiped == true do
		TestPart.Position  =, 5),round(Mouse.hit.p.Y, 5) , round(Mouse.hit.p.Z, 5))

	ToolEquiped = false

	local Block = TestPart:Clone()
	Block.Parent = workspace
	Block.CanCollide = true
	Block.Transparency = 0

Here is a link to the game so that you can see what I mean(There are still other things that I need to fix):

1 Like

It will likely be to do with this.

You are using round for geometric snapping which shouldn’t really be done.

I think you’ll need to work out where the mouse is in relation the the centre of the part and then use math.floor or math.ciel as appropriate.

When you try to place it on that side, your script rounds up the positition so it ends up inside the block you’re trying to place it next to

Yeah I also thought that.

Sorry I am not that good at scripting could you show me how I would do that?

I’m afraid I’m not sure (as a quick answer), I’m more into back-end processing than 3D geometry, just I remembered that post and thought it would be of use, sorry.

1 Like

The geometry is not actually needed if you use the right trick, you just need to be smart about how you’re biasing the block position.

When your mouse click happens, the hit lands exactly on the side of the block, but that means that it’s exactly on the edge between two blocks. Your code has to have some way to disambiguate which of the two potential “sides” of the click to put the block on.

The easiest way to do this is to subtract the camera direction (Camera.CFrame.LookVector) multiplied by a very small bias (like, 0.01 or something), from the hit position. That way you will always choose the empty space (if the space closer to your camera was the full space… the hit would have happened earlier, so the space closer to your camera must be the empty one)

I was able to fix it with help of this post: Object Placement occasionally doesn't work - #5 by Mr_Unlucky