Reduce lag in Voxel game (Need Help)

What do you mean by that you made it invisible?

No. I only hide it from players.

Sorry i am having a hard time understanding what you are saying could you explain a little bit more in detail sorrymy english is not the best

My english is not the best too.
I made a terrain under the map, so you can’t see it no?
Then I saw the terrain with a camera placed under the map, and I saw the terrain.
Simple no?

i am using a cube mesh with 12 triangles is there any way that i can reduce the lag?

Oh i dont use blender and the i dont have any builds rn its just cubes

There’s a program too!
It’s called simplygon: link

Here is the game so you guys can get an idea of what im trying to do.

When adding each part, do you have a wait() between adding each part or chunk of parts?

Yes it does have a wait() but thats only in the beggining of the for i’v loop

local seed = math.random(1000,9000000)
local computerseed = math.random(1000,9000000)
local computerseed2 = math.random(1000,9000000)
local gens = math.random(1,10)
local xblock = 1000
local zblock = 1000
local size = 3
local frequency = math.sin(math.noise(math.rad(seed/computerseed+computerseed2math.noise(gens,seed,gens)),math.rad(seed/computerseed+computerseed2math.noise(gens,seed,gens)),0))
local biome = math.random(1,5)

print(seed)

print(computerseed)
print(computerseed2)

print(frequency)
print(gens)
for x = 1,xblock do
wait()
for z = 1,zblock do
local n = math.noise(xfrequency,zfrequency,0)*300
if biome == 1 then
local p = game.ReplicatedStorage.Block:Clone()
p.Anchored = true
p.TopSurface = “Smooth”
p.BottomSurface = “Smooth”
p.BrickColor = BrickColor.new(“Bright green”)
p.Material = “Plastic”
p.Name = ‘Grass’

		p.CFrame = CFrame.new((x-1-(xblock/2))*size  ,n-(n%size),(z-1-(zblock/2))*size  )
		
		p.Parent = workspace.Map.Blocks
		
	elseif biome == 2 then
		local p = game.ReplicatedStorage.Block:Clone()	
		p.Anchored = true
		p.TopSurface = "Smooth"
		p.BottomSurface = "Smooth"
		p.BrickColor = BrickColor.new("Cork")
		p.Material = "Plastic"
		p.Name = 'Sand'
		  
		p.CFrame = CFrame.new((x-1-(xblock/2))*size  ,n-(n%size),(z-1-(zblock/2))*size  )
		
		p.Parent = workspace.Map.Blocks
		elseif biome == 3 then
		local p = game.ReplicatedStorage.Block:Clone()	
			p.Anchored = true
			p.TopSurface = "Smooth"
			p.BottomSurface = "Smooth"
			p.BrickColor = BrickColor.new("White")
			p.Material = "Plastic"
			p.Name = 'Snow'
			  
		p.CFrame = CFrame.new((x-1-(xblock/2))*size  ,n-(n%size),(z-1-(zblock/2))*size  )
		
		p.Parent = workspace.Map.Blocks
	elseif biome == 4 then
		local p = game.ReplicatedStorage.Block:Clone()		
		p.Anchored = true
		p.TopSurface = "Smooth"
		p.BottomSurface = "Smooth"
		p.BrickColor = BrickColor.new("Bright green")
		p.Material = "Plastic"
		p.Name = 'Grass'
		  
		p.CFrame = CFrame.new((x-1-(xblock/2))*size  ,n-(n%size),(z-1-(zblock/2))*size  )
		
		p.Parent = workspace.Map.Blocks
	else
		local p = game.ReplicatedStorage.Block:Clone()	
		p.Anchored = true
		p.TopSurface = "Smooth"
		p.BottomSurface = "Smooth"
		p.BrickColor = BrickColor.new("Rust")
		p.Material = "Plastic"
		p.Name = 'Mesa'
		  
		p.CFrame = CFrame.new((x-1-(xblock/2))*size  ,n-(n%size),(z-1-(zblock/2))*size  )
		
		p.Parent = workspace.Map.Blocks
		end
		local rl1 = math.random(1,7)
		if rl1 == 1 then
		local r = game.ReplicatedStorage.Block:Clone()	
			r.Anchored = true
			r.TopSurface = "Smooth"
			r.BottomSurface = "Smooth"
			r.BrickColor = BrickColor.new("Dark stone grey")
			r.Material = "Plastic"
			  
			r.Name = 'Stone'
		r.CFrame = CFrame.new((x-1-(xblock/2))*size  ,n-size-(n%size),(z-1-(zblock/2))*size  )
		
		r.Parent = workspace.Map.Blocks
		elseif rl1 == 2 then
		local r = game.ReplicatedStorage.Block:Clone()		
			r.Anchored = true
			r.TopSurface = "Smooth"
			r.BottomSurface = "Smooth"
			r.BrickColor = BrickColor.new("Dark stone grey")
			r.Material = "Plastic"
			  
			r.Name = 'Plastic'
		r.CFrame = CFrame.new((x-1-(xblock/2))*size  ,n-size-(n%size),(z-1-(zblock/2))*size  )
		
		r.Parent = workspace.Map.Blocks
		elseif rl1 == 3 then
		local r = game.ReplicatedStorage.Block:Clone()		
			r.Anchored = true
			r.TopSurface = "Smooth"
			r.BottomSurface = "Smooth"
			r.BrickColor = BrickColor.new("Dark stone grey")
			r.Material = "Plastic"
			  
			r.Name = 'Stone'
		r.CFrame = CFrame.new((x-1-(xblock/2))*size  ,n-size-(n%size),(z-1-(zblock/2))*size  )
		
		r.Parent = workspace.Map.Blocks
		elseif rl1 == 4 then
		local r = game.ReplicatedStorage.Block:Clone()		
			r.Anchored = true
			r.TopSurface = "Smooth"
			r.BottomSurface = "Smooth"
			r.BrickColor = BrickColor.new("Dark stone grey")
			r.Material = "Plastic"
			  
			r.Name = 'Stone'
		r.CFrame = CFrame.new((x-1-(xblock/2))*size  ,n-size-(n%size),(z-1-(zblock/2))*size  )
	
		r.Parent = workspace.Map.Blocks
		elseif rl1 == 5 then
		local r = game.ReplicatedStorage.Block:Clone()	
			r.Anchored = true
			r.TopSurface = "Smooth"
			r.BottomSurface = "Smooth"
			r.BrickColor = BrickColor.new("Dark stone grey")
			r.Material = "Plastic"
			  
			r.Name = 'Stone'
		r.CFrame = CFrame.new((x-1-(xblock/2))*size  ,n-size-(n%size),(z-1-(zblock/2))*size  )
		
		r.Parent = workspace.Map.Blocks
	elseif rl1 == 6 then
		
	else
		
		end
		
	local ra = game.ReplicatedStorage.Block:Clone()		
		ra.Anchored = true
		ra.TopSurface = "Smooth"
		ra.BottomSurface = "Smooth"
		ra.BrickColor = BrickColor.new("Dark stone grey")
		ra.Material = "Plastic"
		ra.Name = 'Stone'
		
	ra.CFrame = CFrame.new((x-1-(xblock/2))*size  ,n-size-size-(n%size),(z-1-(zblock/2))*size  )

		ra.Parent = workspace.Map.Blocks
	local rb = game.ReplicatedStorage.Block:Clone()		
		rb.Anchored = true
		rb.TopSurface = "Smooth"
		rb.BottomSurface = "Smooth"
		rb.BrickColor = BrickColor.new("Dark stone grey")
		rb.Material = "Plastic"
		rb.Name = 'Stone'
		
	rb.CFrame = CFrame.new((x-1-(xblock/2))*size  ,n-size-size-size-(n%size),(z-1-(zblock/2))*size  )
	
		rb.Parent = workspace.Map.Blocks
	local rc = game.ReplicatedStorage.Block:Clone()		
		rc.Anchored = true
		rc.TopSurface = "Smooth"
		rc.BottomSurface = "Smooth"
		rc.BrickColor = BrickColor.new("Dark stone grey")
		rc.Material = "Plastic"
		rc.Name = 'Stone'
		
	rc.CFrame = CFrame.new((x-1-(xblock/2))*size  ,n-size-size-size-size-(n%size),(z-1-(zblock/2))*size  )
	
		rc.Parent = workspace.Map.Blocks
	local rd = game.ReplicatedStorage.Block:Clone()			
		rd.Anchored = true
		rd.TopSurface = "Smooth"
		rd.BottomSurface = "Smooth"
		local rdclr = math.random(1,2)
		if rdclr == 1 then
		
		local rd = game.ReplicatedStorage.Block:Clone()	
			rd.Anchored = true
			rd.TopSurface = "Smooth"
			rd.BottomSurface = "Smooth"
			rd.BrickColor = BrickColor.new("Dark stone grey")
			rd.Material = "Plastic"
			rd.Name = 'Stone'
			  
		rd.CFrame = CFrame.new((x-1-(xblock/2))*size  ,n-size-size-size-size-size-(n%size),(z-1-(zblock/2))*size  )
		
			rd.Parent = workspace.Map.Blocks
		else
		local rd = game.ReplicatedStorage.Block:Clone()	
			rd.Anchored = true
			rd.TopSurface = "Smooth"
			rd.BottomSurface = "Smooth"
			rd.BrickColor = BrickColor.new("Sand red")
			rd.Material = "Plastic"
			rd.Name = 'Iron'
			  
		rd.CFrame = CFrame.new((x-1-(xblock/2))*size  ,n-size-size-size-size-size-(n%size),(z-1-(zblock/2))*size  )
		
			rd.Parent = workspace.Map.Blocks
	end
	local dt = math.random(1,300)
	if dt == 1 then
		local tree = game.ReplicatedStorage.Tree:Clone()
		
		tree.Anchored = true
		tree.CFrame = CFrame.new((x-1-(xblock/2))*size  ,n+4+size-(n%size),(z-1-(zblock/2))*size  )
		tree.Parent = workspace
	else
		
	
	end
	local isCave = math.random(1,100)
	if isCave == 1 then
		local rd = game.ReplicatedStorage.Block:Clone()		
		rd.Anchored = true
		rd.TopSurface = "Smooth"
		rd.BottomSurface = "Smooth"
		rd.BrickColor = BrickColor.new("Dark stone grey")
		rd.Material = "Plastic"
		rd.Name = 'Stone'
		  
		rd.CFrame = CFrame.new((x-1-(xblock/2))*size  ,n-size-size-size-size-size-size-(n%size),(z-1-(zblock/2))*size  )
		
		rd.Parent = workspace.Map.Blocks
	else
		
	end
	local isCaves = math.random(1,999)
	if isCaves == 1 then
		
		else
	end
	local isCave3 = math.random(1,999)
	if isCave3 == 1 then
		
	else
		
	end
	local iscave4 = math.random(1,100)
	if iscave4 == 1 then
		rd.Parent = workspace.Map.Blocks
		local rd = game.ReplicatedStorage.Block:Clone()		
		rd.Anchored = true
		rd.TopSurface = "Smooth"
		rd.BottomSurface = "Smooth"
		rd.BrickColor = BrickColor.new("Dark stone grey")
		rd.Material = "Plastic"
		rd.Name = 'Stone'
		  
		rd.CFrame = CFrame.new((x-1-(xblock/2))*size  ,n-size-size-size-size-size-size-size-size-size-size-(n%size),(z-1-(zblock/2))*size  )
		
		rd.Parent = workspace.Map.Blocks
	else
		
	end
	
	local rd = game.ReplicatedStorage.Block:Clone()	
	rd.Anchored = true
	rd.TopSurface = "Smooth"
	rd.BottomSurface = "Smooth"
	rd.BrickColor = BrickColor.new("Dark stone grey")
	rd.Material = "Plastic"
	rd.Name = 'Stone'
	  
	rd.CFrame = CFrame.new((x-1-(xblock/2))*size  ,n-size-size-size-size-size-size-size-size-size-size-size-(n%size),(z-1-(zblock/2))*size  )
	
	
	rd.Parent = workspace.Map.Blocks
	local rd = Instance.new("Part")		
	local rd = game.ReplicatedStorage.Block:Clone()	
	rd.TopSurface = "Smooth"
	rd.BottomSurface = "Smooth"
	rd.BrickColor = BrickColor.new("Dark stone grey")
	rd.Material = "Plastic"
	rd.Name = 'Stone'
	  
	rd.CFrame = CFrame.new((x-1-(xblock/2))*size  ,n-size-size-size-size-size-size-size-size-size-size-size-size-(n%size),(z-1-(zblock/2))*size  )
	
	rd.Parent = workspace.Map.Blocks
	local rd = game.ReplicatedStorage.Block:Clone()		
	rd.Anchored = true
	rd.TopSurface = "Smooth"
	rd.BottomSurface = "Smooth"
	rd.BrickColor = BrickColor.new("Dark stone grey")
	rd.Material = "Plastic"
	rd.Name = 'Stone'
	  
	rd.CFrame = CFrame.new((x-1-(xblock/2))*size  ,n-size-size-size-size-size-size-size-size-size-size-size-size-size-(n%size),(z-1-(zblock/2))*size  )
	
	rd.Parent = workspace.Map.Blocks
	local rd = game.ReplicatedStorage.Block:Clone()	
	rd.Anchored = true
	rd.TopSurface = "Smooth"
	rd.BottomSurface = "Smooth"
	rd.BrickColor = BrickColor.new("Dark stone grey")
	rd.Material = "Plastic"
	rd.Name = 'Stone'
	  
	rd.CFrame = CFrame.new((x-1-(xblock/2))*size  ,n-size-size-size-size-size-size-size-size-size-size-size-size-size-size-(n%size),(z-1-(zblock/2))*size  )
	
	rd.Parent = workspace.Map.Blocks
	local rd = game.ReplicatedStorage.Block:Clone()	
	rd.Anchored = true
	rd.TopSurface = "Smooth"
	rd.BottomSurface = "Smooth"
	rd.BrickColor = BrickColor.new("Dark stone grey")
	rd.Material = "Plastic"
	rd.Name = 'Stone'
	  
	rd.CFrame = CFrame.new((x-1-(xblock/2))*size  ,n-size-size-size-size-size-size-size-size-size-size-size-size-size-size-size-(n%size),(z-1-(zblock/2))*size  )
	
	rd.Parent = workspace.Map.Blocks
	local rd = game.ReplicatedStorage.Block:Clone()		
	rd.Anchored = true
	rd.TopSurface = "Smooth"
	rd.BottomSurface = "Smooth"
	rd.BrickColor = BrickColor.new("Really red")
	rd.Material = "Plastic"
	rd.Name = 'bedrock'
	  
	rd.CFrame = CFrame.new((x-1-(xblock/2))*size  ,n-size-size-size-size-size-size-size-size-size-size-size-size-size-size-size-size-(n%size),(z-1-(zblock/2))*size  )
	
	rd.Parent = workspace.Map.Blocks
	
	
		
		
	end

end

print("done with gen")

Different part types have different amounts of triangles. A square face is made of two therefore a cube has 12 triangles. Meshes would have the same number unless you had separate meshes for each face and removed meshes outside the map.
Edit: or you could make different meshes for each combination of faces visible.

By the way I played the game and it doesn’t lag or crash, so good work :+1:t2:

yeah i reduced it to an 80x80 chunk

I don’t know if someone mentioned this already as I haven’t looked yet, but you could make a plane (flat surface) in blender, export to roblox, then make the game automatically set the faces depending on if there is no blocks on the side of the face.

I have no idea how to implement this as I am actually making a voxel game but don’t know how I would optimize with this.

(sorry if this is hard to understand, im not good at explaining)

(also you probably did this :I)

1 Like