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