How do i make it so textures get hidden when they dont need to be seen?

what im trying to do is to hide the textures on a face that isnt shown (basically if theres a block next to another block it hides the texture on the face that is next to it)
image
its to prevent this. (and to remove lag)
i have tried myself and tried looking it up but no luck.
(sorry if im bad at explaining)

What I’ve done in the past with my game Island Miners was to set the names based on their coordinates divided by the voxel size. For example, 1x1x1, 2x1x1 – I then check neighboring cells based on taking those coordinates and adding / subtracting on each axis. Since there’s only 6 possible sides on a voxel, it’d look something like this;

local Directions = {
	{Offset = Vector3.new(1,0,0), Surface = Enum.NormalId.Right},
	{Offset = Vector3.new(-1,0,0), Surface = Enum.NormalId.Left},
	{Offset = Vector3.new(0,1,0), Surface = Enum.NormalId.Top},
	{Offset = Vector3.new(0,-1,0), Surface = Enum.NormalId.Bottom},
	{Offset = Vector3.new(0,0,1), Surface = Enum.NormalId.Back},
	{Offset = Vector3.new(0,0,-1), Surface = Enum.NormalId.Front},
}

local Surfaces = {
	Enum.NormalId.Top,
	Enum.NormalId.Bottom,
	Enum.NormalId.Left,
	Enum.NormalId.Right,
	Enum.NormalId.Front,
	Enum.NormalId.Back
}

local Voxels = {}
local VoxelSize = 4

for x = 1, 10 do
	for y = 1, 3 do
		for z = 1, 10 do
			Voxels[x..'x'..y..'x'..z] = math.random(1,6) -- block type ID
			local Part = Instance.new('Part')
			Part.Name = x..'x'..y..'x'..z
			Part.Size = Vector3.new(VoxelSize,VoxelSize,VoxelSize)
			Part.Anchored = true
			Part.CFrame = CFrame.new((x-1)*VoxelSize,(y-1)*VoxelSize,(z-1)*VoxelSize)
			for i,v in pairs(Surfaces) do
				local Decal = Instance.new('Decal')
				Decal.Name = tostring(v)
				Decal.Texture = 'http://www.roblox.com/asset/?id=12351989257'
				Decal.Face = v
				Decal.Parent = Part
			end
			Part.Parent = workspace
		end
	end
end

for i,v in pairs(Voxels) do
	local coordinates = string.split(i,'x')
	
	local Pos = Vector3.new(coordinates[1],coordinates[2],coordinates[3])
	for i,v in ipairs(Directions) do
		local Offset = v.Offset
		local Neighbor = Pos.X-Offset.X..'x'..Pos.Y-Offset.Y..'x'..Pos.Z-Offset.Z
		
		
		if Voxels[Neighbor] then
			local NeighorBlock = workspace:findFirstChild(Neighbor)
			
			if NeighorBlock then
				local NeighborSurface = NeighorBlock:findFirstChild(tostring(v.Surface))
				if NeighborSurface then
					NeighborSurface:Destroy()
				end
			end
		end
	end
end

Here’s the result:
image

I also use something similar to remove blocks you can’t see to reduce lag

1 Like

ill check it out, cant right now though.

though i cant make the coordinates in an easy way because theres also breaking and building which i have a different system than you probably

My game allows you to build / remove blocks from your own island, a little more complex than the code I provided, but when you place a block, you can check surrounding based on that coordinate. When you remove a block, iterate through the surrounding blocks and show the textures again. Check the game out and you’ll see. :slight_smile:

2 Likes

oh though i found a script on devforum from here just now. but i just have to tweak the building script and the script itself for it to work properly, ill tweak it and come back with a solution for everyone else who is looking for the answer. anyways i appreciate your help :slight_smile:

Maybe what you want to do instead is fusing parts whenever their neighbors are of the same type.
Greedy Meshing Algorithm - Roblox Scripting Tutorial - YouTube

1 Like

Aah… Mine was written in such a way to make it easier to save / load the builds without potential of floating point inaccuracies eating up a bunch of characters — that’s why I had it formatted the way I did. Good luck! :slight_smile: