Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Trying to make a chunk loader, but its crazy?

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()

4 comments

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.

0

https://www.youtube.com/watch?v=UkaK9Qx17zY - World Generation by SpooksHD

0

look at my video, also that world generation is really random

0

I'm just giving ideas.

2 answers

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.