Voxel generation is not changing transparency on some parts

I am trying to make a voxel game but the way I generate stuff doesn’t work some of the time with seemingly no reason.

When I try to load the parts, some of them just don’t load and I don’t know why
The parts are still there but they have transparency 1 still

The game – vtg - Roblox

I’ve tried looking this problem up, changing how the generation works, putting it on the server, but nothing seems to solve this problem.

the way this generation works is by finding the blocks with the name by putting the x y and z in the name for example: vector3.new(0,0,0) – position of block, would change the name to be 000 and you would be able to find it using :FindFirstChild()
– script for generating on server in workspace

local seed = math.random(1, 1000)

local MAPSIZE = 50

local MAPSCALE = MAPSIZE/2
local downtendency = 1
local upmulti = 1
print(upmulti)
array = { --- was scrapped due to table.find not working with what i wanted
	
}
function check(x,y,z)
	
	if workspace.Folder:FindFirstChild(x..y ..z) == nil then
		local block = Instance.new("Part",workspace)
		block.Size = Vector3.new(4,4,4)
		block.Anchored = true
		block.Position = Vector3.new(x, y , z)
		block.Parent = workspace.Folder
		block.Transparency = 1
		block.Material = Enum.Material.SmoothPlastic
		block.Name = block.Position.X..block.Position.Y..block.Position.z
		block.Color = Color3.new(0.33, 0.61, 0.35)
	end
end
function tree(originx,originy,originz)
	local lastblock = nil
	local ran = math.random(4,10)
	for i = 1,ran,1 do
		if lastblock ~= nil then
			if workspace.Folder:FindFirstChild(lastblock.Position.X..lastblock.Position.Y+4 ..lastblock.Position.Z) ~= nil then
				i = ran
			else
				local block = Instance.new("Part",workspace)
				block.Size = Vector3.new(4,4,4)
				block.Anchored = true
				local x = originx
				local y = originy
				local z = originz

				block.Position = Vector3.new(x, y + i * 4, z)

				block.Parent = workspace.Folder
				local number = Instance.new("NumberValue",block)
				number.Value = i
				block.Transparency = 1
				block.Material = Enum.Material.SmoothPlastic
				if workspace.Folder:FindFirstChild(block.Position.X..block.Position.Y..block.Position.z) ~= nil then
					workspace.Folder:FindFirstChild(block.Position.X..block.Position.Y..block.Position.z):Destroy()

				end
				block.Name = block.Position.X..block.Position.Y..block.Position.z
				block.Color = Color3.new(0.7, 0.34, 0.08)
				lastblock = block
			end	
		else
			local block = Instance.new("Part",workspace)
			block.Size = Vector3.new(4,4,4)
			block.Anchored = true
			local x = originx
			local y = originy
			local z = originz

			block.Position = Vector3.new(x, y + i * 4, z)

			block.Parent = workspace.Folder
			local number = Instance.new("NumberValue",block)
			number.Value = i
			block.Transparency = 1
			block.Material = Enum.Material.SmoothPlastic
			if workspace.Folder:FindFirstChild(block.Position.X..block.Position.Y..block.Position.z) ~= nil then
				workspace.Folder:FindFirstChild(block.Position.X..block.Position.Y..block.Position.z):Destroy()

			end
			block.Name = block.Position.X..block.Position.Y..block.Position.z
			block.Color = Color3.new(0.7, 0.34, 0.08)
			lastblock = block
		end

	
	
	end
	local x = lastblock.Position.X 
	local y = lastblock.Position.Y + 4
	local z = lastblock.Position.Z
	
	check(x,y,z)
	local x = lastblock.Position.X 
	local y = lastblock.Position.Y + 8
	local z = lastblock.Position.Z

	check(x,y,z)
	local x = lastblock.Position.X -4
	local y = lastblock.Position.Y 
	local z = lastblock.Position.Z

	check(x,y,z)
	local x = lastblock.Position.X + 4
	local y = lastblock.Position.Y 
	local z = lastblock.Position.Z

	check(x,y,z)
	local x = lastblock.Position.X 
	local y = lastblock.Position.Y 
	local z = lastblock.Position.Z -4

	check(x,y,z)
	local x = lastblock.Position.X 
	local y = lastblock.Position.Y 
	local z = lastblock.Position.Z + 4

	check(x,y,z)
	
	local x = lastblock.Position.X + 4
	local y = lastblock.Position.Y 
	local z = lastblock.Position.Z + 4

	check(x,y,z)
	local x = lastblock.Position.X - 4
	local y = lastblock.Position.Y 
	local z = lastblock.Position.Z + 4

	check(x,y,z)
	local x = lastblock.Position.X - 4
	local y = lastblock.Position.Y 
	local z = lastblock.Position.Z - 4

	check(x,y,z)
	local x = lastblock.Position.X + 4
	local y = lastblock.Position.Y 
	local z = lastblock.Position.Z - 4

	check(x,y,z)
	local x = lastblock.Position.X + 4
	local y = lastblock.Position.Y + 4
	local z = lastblock.Position.Z - 4

	check(x,y,z)
	local x = lastblock.Position.X + 4
	local y = lastblock.Position.Y + 4
	local z = lastblock.Position.Z + 4

	check(x,y,z)
	local x = lastblock.Position.X - 4
	local y = lastblock.Position.Y + 4
	local z = lastblock.Position.Z + 4

	check(x,y,z)
	local x = lastblock.Position.X - 4
	local y = lastblock.Position.Y + 4
	local z = lastblock.Position.Z - 4

	check(x,y,z)
	local x = lastblock.Position.X 
	local y = lastblock.Position.Y + 4
	local z = lastblock.Position.Z - 4

	check(x,y,z)
	local x = lastblock.Position.X 
	local y = lastblock.Position.Y + 4
	local z = lastblock.Position.Z + 4

	check(x,y,z)
	local x = lastblock.Position.X - 4
	local y = lastblock.Position.Y + 4
	local z = lastblock.Position.Z 

	check(x,y,z)
	local x = lastblock.Position.X + 4
	local y = lastblock.Position.Y + 4
	local z = lastblock.Position.Z 

	check(x,y,z)
end
local load = 1 
function loadup()
for xAxis = MAPSIZE/3,MAPSIZE do
	for zAxis = MAPSIZE/3,MAPSIZE do
		
		local noise = math.noise(seed, xAxis/12, zAxis/12)*8
		local block = Instance.new("Part",workspace)
		block.Size = Vector3.new(4,4,4)
		block.Anchored = true
		local x = math.floor(xAxis*4)
		local y = math.floor(noise/downtendency)*(upmulti*4) 
		local z = math.floor(zAxis*4)
		block.Position = Vector3.new(-MAPSIZE * 3,0,-MAPSIZE * 3)
		block.Position = block.Position + Vector3.new(x, y, z)
			if math.random(1,30) == 1 then
				tree(block.Position.X,block.Position.Y,block.Position.Z)
			end
		block.Parent = workspace.Folder
			block.Transparency = 1
			block.Material = Enum.Material.SmoothPlastic
		--table.insert(array,load,{x,y,z})
			block.Name = block.Position.X..block.Position.Y..block.Position.z
			block.Color = Color3.new(0.52, 0.85, 0.34)
		load = load + 1
		local i = 1
		if math.floor(load) % 16 == 0 then
				task.wait()
		end
		repeat
			
		
			local noise = math.noise(seed, xAxis/12, zAxis/12)*8
			local block = Instance.new("Part",workspace)
			block.Size = Vector3.new(4,4,4)
			block.Transparency = 1
				block.Anchored = true
				block.Material = Enum.Material.SmoothPlastic
				if i <= 2 then
					block.Color = Color3.new(0.56, 0.4, 0.24)
				end
			local x = math.floor(xAxis*4)
			local y = math.floor(noise/downtendency)*(upmulti*4) 
				local z = math.floor(zAxis*4)
				block.Position = Vector3.new(-MAPSIZE * 3,0,-MAPSIZE * 3)
			block.Position = block.Position + Vector3.new(x, y- 4 * i, z)
			block.Parent = workspace.Folder
			--table.insert(array,load,{x,y,z})
				block.Name = block.Position.X..block.Position.Y..block.Position.z
			load = load + 1
			i = i + 1
		until block.Position.Y < -40
	end
end	
end

loadup()

workspace.loaded.Value = true

script.RemoteEvent.OnServerEvent:Connect(function(plr,chosen)
	chosen:Destroy()
end)


– local script in playerscripts

function sides(chosen,destroyed)
	local ez = 0
	local x = chosen.Position.X
	local y = chosen.Position.Y
	local z = chosen.Position.Z
	
	if workspace.Folder:FindFirstChild(x..math.floor(y-4) ..z) == nil  then
		

		chosen.Transparency =0
	
		end
	if workspace.Folder:FindFirstChild(x..math.floor(y+4) ..z) == nil  then

			chosen.Transparency = 0
		end
		
	if  workspace.Folder:FindFirstChild(math.floor(x+4) ..y ..z) == nil  then

		chosen.Transparency = 0
		
end
	if workspace.Folder:FindFirstChild(math.floor(x-4) ..y ..z) == nil  then

		chosen.Transparency = 0
end
	if workspace.Folder:FindFirstChild(x ..y ..math.floor(z+4)) == nil  then

		chosen.Transparency = 0
end
	if workspace.Folder:FindFirstChild(x ..y ..math.floor(z-4)) == nil  then
	
		chosen.Transparency = 0
	
	end
	if destroyed ~= nil then
		if workspace.Folder:FindFirstChild(x..y-4 ..z) ~= nil then
			workspace.Folder:FindFirstChild(x..y-4 ..z).Transparency = 0

		end
		if workspace.Folder:FindFirstChild(x..y+4 ..z) ~= nil then
			workspace.Folder:FindFirstChild(x..y+4 ..z).Transparency = 0
		end
		if workspace.Folder:FindFirstChild(x-4 ..y ..z) ~= nil then
			workspace.Folder:FindFirstChild(x-4 ..y ..z).Transparency = 0
		end
		if workspace.Folder:FindFirstChild(x+4 ..y ..z) ~= nil then
			workspace.Folder:FindFirstChild(x+4 ..y ..z).Transparency = 0
		end
		if workspace.Folder:FindFirstChild(x..y ..z-4) ~= nil then
			workspace.Folder:FindFirstChild(x..y ..z-4).Transparency = 0
		end
		if workspace.Folder:FindFirstChild(x..y ..z+4) ~= nil then
			workspace.Folder:FindFirstChild(x..y ..z+4).Transparency = 0
		end
		chosen:Destroy()
	end


end
function load()
	

	for i = 1,#workspace.Folder:GetChildren() do
		local chosen = workspace.Folder:GetChildren()[i]
		if chosen ~= nil then
			
		
			sides(chosen)
		end
		if math.floor(i) % 32 == 0 then
			task.wait()
			end
		
	end
	for i = 1,#workspace.Folder:GetChildren() do
		local chosen = workspace.Folder:GetChildren()[i]
		if chosen ~= nil then
			if chosen.Transparency == 1 then
				sides(chosen)
			end

			
		end
		if math.floor(i) % 32 == 0 then
			task.wait()
		end

	end
end
workspace.loaded.Changed:Connect(function(val)
	if val then
		
		load()
		
	end
end)

Any help would be greatly appreciated
Thanks in advance!

If you change the name of parts to their position so position 0,0,0 becomes 000, wouldn’t there be overlaps? For example, part at pos (3, 12, 2) will have the same name as part at pos (31,2,2).
The reason why some parts didn’t load might be because there are multiple parts with same names.

1 Like

oh my god i totally forgot that was an option let me try fixing that
edit: yep that was the problem