New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Still have questions? Join our Discord server and get real time help.
Log in to vote

How do I make the block go into the correct place? [SOLVED]

Asked by 3 months ago
Edited by BashCaster 3 months ago

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 = + 2, y + 2, z + 2)

    local part ="Part", workspace)
    part.Size =,4,4)
    part.Position = position
    part.Anchored = true
    if material.Value == 1 then
        part.Material = Enum.Material.WoodPlanks
        part.BrickColor =
    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()

Help would be appreciated. Thank you!

2 answers

Log in to vote
Answered by
Markdrg 15
3 months ago

Kinda easy Basically just

Just make all those 2s on line 10 1

So it would be

local position = + 1, y + 1, z + 1)
That wouldn't work, since each of my blocks are 4 x 4 x 4 studs flunkywhat 27 — 3mo
Ah. Markdrg 15 — 3mo
Log in to vote
Answered by 3 months ago

I fixed it by making the original click position offsetted by 2, then after rounding subtracting 2, and it fixed it.

Answer this question