need help fixing chunking system on roblox

i can’t find any particular reason for this but whenever i attempt loading chunks all of the blocks appear at the same coordinate

this is really frustrating and i cannot find a fix to it

im working on infinite voxel terrain but everytime the code places a block with the chunk system i’ve made it all goes in a specific spot for each chunk and i’ve tried storing the position in a table but still can’t get it to work

here’s my code for the world generation;

local blockContainer = workspace.World
local intlimit = 100
local seed = Random.new():NextInteger(-intlimit, intlimit)
local chunks = game.ServerStorage.storage.req.chunks
local clamprange = 0.5
local fogScreenSize = 16 -- default 100
local resolution = 100 -- default 100
local frequency = 1.5 -- default 3
local amplitude = 10 -- default 12
local spawnchunkvector = Vector3.new(0, 0, 0)

function getHeight(x, z)
    local noiseHeight = math.noise((x/resolution*frequency), seed, (z/resolution*frequency))

    noiseHeight = math.clamp(noiseHeight, -clamprange, clamprange) + 0.5

    return noiseHeight
end

function incsnap(n, to)
    return math.floor(n/to + 0.5) * to
end

function placeblock(block:string, pos:Vector3)
    return require(game.ReplicatedStorage.bin.shared.mc_modules.mappings).placeblock(block, pos)
end

function placetree(origin, height)
    local tree = Instance.new("Model")
    local stump = placeblock("log", origin)
    local toplog = stump

    stump.Parent = tree

    -- make logs & stump

    spawn(function()
        for y = 0, height do
            local log = placeblock("log", origin + Vector3.new(0, 3, 0))

            origin += Vector3.new(0, 3, 0)
            log.Parent = tree
            toplog = log
        end
    end)

    -- make leaves

    spawn(function()

    end)

    return tree
end

--[[function old_generate()
    blockContainer:ClearAllChildren()

    for x = 0, fogScreenSize do
        for z = 0, fogScreenSize do
            local y = getHeight(x, z)
            local blocktype = "grass"
            local block = placeblock(blocktype, Vector3.new(x*3, incsnap(math.round((y*amplitude * 6)), 3), z*3))

            block.Parent = blockContainer
            print("Generated block @ "..tostring(block.Position))

            if (Random.new():NextInteger(1, 100) == 1) then
                local tree = placetree(block.Position + Vector3.new(0, 3, 0), Random.new():NextInteger(3, 5))

                tree.Parent = blockContainer

                print("Spawned tree @ "..tostring(block.Position))
            end
        end

        game:GetService("RunService").Heartbeat:Wait()
    end
end]]

function cacheChunk(chunk:Folder)
    local templateblockdata = {
        ['blocktype'] = nil;
        ['position'] = nil;
        ['rot'] = nil;
    }
    local memory = {['chunkdata'] = {
        ['blocks'] = {

        }
    }}

    for i, b in pairs(chunk:GetChildren()) do
        if b:IsA("BasePart") then
            local blockdata = templateblockdata

            blockdata.blocktype = b.Name
            blockdata.position = {
                ['X'] = b.Position.X;
                ['Y'] = b.Position.Y;
                ['Z'] = b.Position.Z;
            }
            blockdata.rot = b.Orientation

            table.insert(memory.chunkdata.blocks, blockdata)
        end
    end

    --print("ChunkDataCache:n"..tostring(memory.chunkdata))
    require(chunks).chunks[chunk.Name] = memory.chunkdata
end

function generateChunk(pos:Vector3)
    local folder = Instance.new("Folder")

    folder.Name = tostring(pos)

    for x = 0, fogScreenSize do
        for z = 0, fogScreenSize do
            local y = getHeight(x, z)
            local blocktype = "grass"
            local blockpos = Vector3.new((x*3) + pos.X, incsnap(math.round((y*amplitude * 6)), 3), (z*3) + pos.Z)
            local block = placeblock(blocktype, blockpos)

            block.Parent = folder
            --print("Generated block @ "..tostring(block.Position))

            if (Random.new():NextInteger(1, 100) == 1) then
                local tree = placetree(block.Position + Vector3.new(0, 3, 0), Random.new():NextInteger(3, 5))

                tree.Parent = folder

                --print("Spawned tree @ "..tostring(block.Position))
            end
        end

        --game:GetService("RunService").Heartbeat:Wait()
    end

    cacheChunk(folder)

    return folder
end

function loadChunk(chunk:string)
    if require(chunks).chunks[chunk] ~= nil then
        local chunkdata = require(chunks).chunks[chunk]
        local chunkfolder = Instance.new("Folder")

        chunkfolder.Name = chunk
        chunkfolder.Parent = workspace.World

        for _, b in pairs(chunkdata.blocks) do
            local blocktype = b.blocktype
            local pos = Vector3.new(b.position.X, b.position.Y, b.position.Z)
            local world_block = placeblock(blocktype, pos)

            world_block.Orientation = b.rot
            world_block.Parent = chunkfolder
        end
    else
        -- invalid chunk identifier
        error("Invalid chunk ID!")
    end
end

function unloadChunk(chunk:Folder)
    cacheChunk(chunk)
    chunk:Destroy()
end

-- test code

generateChunk(spawnchunkvector)
loadChunk(tostring(spawnchunkvector))

generateChunk(Vector3.new(0, 0, 16))
loadChunk("0, 0, 16")

spawn(function()
    while true do
        task.wait(1)
        unloadChunk(blockContainer[tostring(spawnchunkvector)])
        task.wait(1)
        loadChunk(tostring(spawnchunkvector))
    end
end)

-- loadChunk(Vector2.new(0, 0)) -- make sure spawn is loaded --Vector3.new(-(fogScreenSize / 2), 0, -(fogScreenSize / 2))

function saveGame()
    if game.PlaceId ~= 17309654844 then
        game:GetService("AssetService"):SavePlaceAsync()
    else
        print("Cannot save during tests")
    end
end

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật