How do I make the block go into the correct place? [SOLVED]
I'm building a Minecraft Spin-off for Roblox, and I have a working 4-block grid placement system, but most of the time the blocks are off by one snapping point. Although it depends on where on the block you tap, click, it sometimes, only sometimes goes to the incorrect block. Here's a snippet of code showing the build function. All of the building controls are binded to the function.
02 | local x = mouse.Hit.p.X |
03 | local y = mouse.Hit.p.Y |
04 | local z = mouse.Hit.p.Z |
10 | local position = Vector 3. new(x + 2 , y + 2 , z + 2 ) |
12 | local part = Instance.new( "Part" , workspace) |
13 | part.Size = Vector 3. new( 4 , 4 , 4 ) |
14 | part.Position = position |
16 | if material.Value = = 1 then |
17 | part.Material = Enum.Material.WoodPlanks |
18 | part.BrickColor = BrickColor.new( 38 ) |
19 | elseif material.Value = = 2 then |
20 | part.Material = Enum.Material.Brick |
21 | part.BrickColor = BrickColor.Red() |
22 | elseif material.Value = = 2 then |
23 | part.Material = Enum.Material.Cobblestone |
24 | part.BrickColor = BrickColor.Gray() |
Help would be appreciated. Thank you!