Help creating a system to delete textures between parts

Hey, devs!

I’ve been working on a new project, and every part has the default texture of the baseplate on every side. I’ve been messing around trying to come up with a way to delete unnecessary textures between parts to hopefully improve performance, and so there isn’t wide ugly lines between every part.

I have looked on the DevForum a little to try and find a better way, but I haven’t, and my system is a little buggy, and tinkering around hasn’t fixed it.

This is my current code for the system:

function module:RemoveTextures(parts: {BasePart})
	local params = RaycastParams.new()
	params.FilterType = Enum.RaycastFilterType.Include
	params.FilterDescendantsInstances = parts
	params.IgnoreWater = true

	for _, part in parts do
		local frontRaycast = workspace:Raycast(part.Position, part.Position + part.CFrame.LookVector, params)
		local backRaycast = workspace:Raycast(part.Position, part.Position + -part.CFrame.LookVector, params)
		local rightRaycast = workspace:Raycast(part.Position, part.Position + part.CFrame.RightVector, params)
		local leftRaycast = workspace:Raycast(part.Position, part.Position + -part.CFrame.RightVector, params)
		local topRaycast = workspace:Raycast(part.Position, part.Position + part.CFrame.UpVector, params)
		local bottomRaycast = workspace:Raycast(part.Position, part.Position + -part.CFrame.UpVector, params)
		
		if frontRaycast and frontRaycast.Instance then if not frontRaycast.Instance:HasTag("Checkpoint") then part:FindFirstChild("Front"):Destroy() end end
		if backRaycast and backRaycast.Instance then if not backRaycast.Instance:HasTag("Checkpoint") then part:FindFirstChild("Back"):Destroy() end end
		if rightRaycast and rightRaycast.Instance then if not rightRaycast.Instance:HasTag("Checkpoint") then part:FindFirstChild("Right"):Destroy() end end
		if leftRaycast and leftRaycast.Instance then if not leftRaycast.Instance:HasTag("Checkpoint") then part:FindFirstChild("Left"):Destroy() end end
		if topRaycast and topRaycast.Instance then if not topRaycast.Instance:HasTag("Checkpoint") then part:FindFirstChild("Top"):Destroy() end end
		if bottomRaycast and bottomRaycast.Instance then if not bottomRaycast.Instance:HasTag("Checkpoint") then part:FindFirstChild("Bottom"):Destroy() end end
	end
end

Every texture in the part is named on the side it’s on.


The parts table is given by another function in the module that returns a table from CollectionService. Both are ran on the server.

This is that server line, and the other function:

model:RemoveTextures(model.get("Part"))
function module.get(tag): {Instance}
	local tagged = collectionService:GetTagged(tag)
	return tagged
end

When I run the game, only two parts get their textures removed entirely. They have no textures after, but the rest of the parts still have all six textures.
Here’s a screenshot:


I don’t need a full new script, I just want some ideas on how to change and fix it.
Any and all help is appreciated. Thank you!!

Best regards,
Amora

2 Likes

The raycasts are only one stud long.

Notice how the parts with their textures removed are next to wedges that are 2 studs thick in the middle, so a one stud raycast from the center would hit the blocks with removed textures.

You should make the raycasts longer by multiplying the vectors (LookVector, RightVector, UpVector) by a large value.

I have tried this. I forgot to mention that, so my apologies. I multiplied it by five, then even 100. It still didn’t work right. And it’s ideal for it to be one stud since I only want the textures to be removed from parts that are touching.

As well as yes, the textures were removed from those parts, but every single one of the textures. I need it to only be on the surfaces being touched

I think for the raycasts, you should cast them from the edges of the part, rather than from the center.

For the textures getting removed on the top, what I would do is check the normal of the raycast result, then use that to determine which face of the part was hit and therefore which texture to remove.

Neither of the two worked, unfortunately