Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
A_thruZ 29
5 years ago
Edited by DeceptiveCaster 5 years 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 = 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!

2 answers

Log in to vote
0
Answered by
Markdrg 15
5 years ago

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)
0
That wouldn't work, since each of my blocks are 4 x 4 x 4 studs A_thruZ 29 — 5y
0
Ah. Markdrg 15 — 5y
Ad
Log in to vote
0
Answered by
A_thruZ 29
5 years 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