Block Positioning not working properly

Hello devs!

So, Im making a basic grid placement system where a block is placed on where the player clicks.

My Objective Is: When a player clicks on a side of a already-placed block, a block will be placed in the side the player clicked.

The Problem: Well, it is working, but when I try to place the block in the bottom and in one of the sides, the block is not placed, it is placed inside the block I clicked.

Video:

My current code is:

	if table.find(objects, block) then
				local X = math.floor(mouseHit.Position.X/2 + 0.5) * 2
				local Y = math.floor(mouseHit.Position.Y/2 + 0.5) * 2
				local Z = math.floor(mouseHit.Position.Z/2 + 0.5) * 2
				block.Position = Vector3.new(X,Y,Z)
	end

Any help is appreciated.

You need to take into account the surface normal of the block you’re trying to place next to, so you know in what direction to offset the placement

This kind of problem has been answered numerous times on the forum.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.