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

Bad argument materials to 'WriteVoxels' (2x1x1 array expected) what did i do wrong?

Asked by 7 years ago

im making a pickaxe that isn't working because i keep getting the error: Bad argument materials to 'WriteVoxels' (2x1x1 array expected)

full code

local mouse
local debounce

script.Parent.Equipped:connect(function(m)
    mouse = m
end)

local function create3dTable(size)
    local ret = {}
    for x = 1, size.X do
        ret[x] = {}
        for y = 1, size.Y do
            ret[x][y] = {}
        end
    end 
    return ret
end

local material = create3dTable(Vector3.new(1,1,4))
material[1][1][1] = Enum.Material.Air
material[1][1][2] = Enum.Material.Air
material[1][1][3] = Enum.Material.Air
material[1][1][4] = Enum.Material.Air

local occupancy = create3dTable(Vector3.new(1,1,4))
occupancy[1][1][1] = 1
occupancy[1][1][2] = 1
occupancy[1][1][3] = 1
occupancy[1][1][4] = 1

script.Parent.Activated:connect(function()
    if not debounce and mouse.Target == game.Workspace.Terrain then
        if (script.Parent.Handle.Position - mouse.Hit.p).magnitude < 10 then
            local region = Region3.new(mouse.Hit.p, mouse.Hit.p+Vector3.new(1,1,1))
            region = region:ExpandToGrid(4)
            game.Workspace.Terrain:WriteVoxels(region, 4, material, occupancy)
        end
    end
end)

Answer this question