Ad
Log in to vote
1

Trying to make a chunk loader, but its crazy?

Asked by
enes223 312 Moderation Voter
2 years ago
Edited 2 years ago

I'm trying to make a game like minecraft but my chunk loader is just a bit crazy.

Video

Source Code:


--By enes223 local prefabStorage = game:GetService("ReplicatedStorage") local Prefabs = { ["Grass"] = prefabStorage:WaitForChild("Grass") } local chunkX = 16 local chunkY = 64 local chunkZ = 16 local chunkSize = Vector3.new(chunkX,chunkY,chunkZ) local chunkPosX = 0 local chunkPosY = 0 local chunkPosZ = 0 local chunkPos = Vector3.new(chunkPosX,chunkPosY,chunkPosZ) local chunkNumber = 0 local Seed = math.random(0,10000000)/100 local noiseScale = 25 local Amplitude = 15 local blockNum = 0 local function createChunk() local primarySelected = false local chunkGroup = Instance.new("Model") chunkGroup.Name = "Chunk"..chunkNumber chunkGroup.Parent = game.Workspace.Terrain for x = chunkPosX-1,chunkX do for y = chunkPosY-1,chunkY do for z = chunkPosZ-1,chunkZ do local noiseX = math.noise(y/noiseScale,z/noiseScale,Seed) * Amplitude local noiseY = math.noise(x/noiseScale,z/noiseScale,Seed) * Amplitude local noiseZ = math.noise(x/noiseScale,y/noiseScale,Seed) * Amplitude local Density = noiseX + noiseY + noiseZ + y if Density < 10 then local Block = Prefabs.Grass:Clone() Block.Position = Vector3.new(x*Block.Size.X,y*Block.Size.Y,z*Block.Size.Z) Block.Parent = chunkGroup if not primarySelected then chunkGroup.PrimaryPart = Block primarySelected = true end end end end blockNum = 0 end chunkNumber = chunkNumber + 1 chunkPos = chunkPos + Vector3.new(1*chunkSize.X,0,1*chunkSize.Z) chunkPosX = chunkPos.X chunkPosY = chunkPos.Y chunkPosZ = chunkPos.Z end createChunk() createChunk()
0
When you use the built in hyperlink format, you put the text you want to appear in the brackets [], then the url to link to in the parenthesis (). Your youtube link opens to _blank. InfinityDesign 280 — 2y
0
https://www.youtube.com/watch?v=UkaK9Qx17zY - World Generation by SpooksHD killerbrenden 1537 — 2y
0
look at my video, also that world generation is really random enes223 312 — 2y
0
I'm just giving ideas. killerbrenden 1537 — 2y

2 answers

Log in to vote
0
Answered by 2 years ago

Roblox actually already has this built for you, and it's called Streaming. you can enable it by setting workspace.StreamingEnabled to true and can control the minimum and maximum streaming radius with workspace.StreamingMinRadius and workspace.StreamingTargetRadius

learn more here

Ad
Log in to vote
0
Answered by
enes223 312 Moderation Voter
2 years ago

Nevermind, I found a way to fix, I changed to method, thanks for trying to help.

Video

Final Code:

--By enes223

local prefabStorage = game:GetService("ReplicatedStorage")

local Prefabs = {
    ["Grass"] = prefabStorage:WaitForChild("Grass")
}

local chunkX = 8
local chunkY = 16
local chunkZ = 8
local chunkSize = Vector3.new(chunkX,chunkY,chunkZ)

local chunkPosX = 0
local chunkPosY = 0
local chunkPosZ = 0
local chunkPos = Vector3.new(chunkPosX,chunkPosY,chunkPosZ)

local chunkNumber = 0

local Seed = math.random(1,10000000)/100

local noiseScale = 25
local Amplitude = 15

local function createChunk(chunkP)
    local primarySelected = false

    local chunkGroup = Instance.new("Model")
    chunkGroup.Name = "Chunk"..chunkNumber
    chunkGroup.Parent = game.Workspace.Terrain

    chunkP = chunkP * chunkSize

    for x = chunkP.X,chunkX + chunkP.X do
        for y = chunkP.Y,chunkY + chunkP.Y do
            for z = chunkP.Z,chunkZ + chunkP.Z do
                local noiseX = math.noise(y/noiseScale,z/noiseScale,Seed) * Amplitude
                local noiseY = math.noise(x/noiseScale,z/noiseScale,Seed) * Amplitude
                local noiseZ = math.noise(x/noiseScale,y/noiseScale,Seed) * Amplitude

                local Density = noiseX + noiseY + noiseZ + y

                if Density < 10 then
                    local Block = Prefabs.Grass:Clone()
                    Block.Parent = chunkGroup
                    Block.Position = Vector3.new(x*Block.Size.X,y*Block.Size.Y,z*Block.Size.Z)

                    if not primarySelected then
                        chunkGroup.PrimaryPart = Block
                        primarySelected = true
                    end
                end
            end
        end
    end
    chunkNumber = chunkNumber + 1

    return chunkGroup
end

for i = 1,10 do
    for v = 1,10 do
        createChunk(Vector3.new(i,0,v))
    end
end

Answer this question