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.
local function build() local x = mouse.Hit.p.X local y = mouse.Hit.p.Y local z = mouse.Hit.p.Z x = (round(x/4) * 4) y = (round(y/4) * 4) z = (round(z/4) * 4) local position = Vector3.new(x + 2, y + 2, z + 2) local part = Instance.new("Part", workspace) part.Size = Vector3.new(4,4,4) part.Position = position part.Anchored = true if material.Value == 1 then part.Material = Enum.Material.WoodPlanks part.BrickColor = BrickColor.new(38) elseif material.Value == 2 then part.Material = Enum.Material.Brick part.BrickColor = BrickColor.Red() elseif material.Value == 2 then part.Material = Enum.Material.Cobblestone part.BrickColor = BrickColor.Gray() end end
Help would be appreciated. Thank you!
Kinda easy Basically just
Just make all those 2s on line 10 1
So it would be
local position = Vector3.new(x + 1, y + 1, z + 1)
I fixed it by making the original click position offsetted by 2, then after rounding subtracting 2, and it fixed it.