Hello, I’m working on a game that has a ton of decals and it causes a lot of lag, and I needed to hide them if they get too far. I made this script to combat this issue, but it tanks the FPS and I am wondering if there is any further optimization available for it.
local plr = game:GetService("Players").LocalPlayer
local runService = game:GetService("RunService")
local distance = 100
runService.RenderStepped:Connect(function(delta)
local stuff = game.Workspace.GearWalls:GetDescendants()
for _,v in pairs(stuff) do
if string.find(v.Name,"Button_") then
local plrDistance = plr:DistanceFromCharacter(v.Position)
--print("is button")
if v:FindFirstChildWhichIsA("Decal") then
v:FindFirstChildWhichIsA("Decal").Transparency = math.round(math.clamp(plrDistance,0,distance)/distance)
end
end
end
end)
Any help is appreciated.