Does this cause more lag?

I have a difficulty chart with 200 stages of obby, I noticed many people are laggy and not many people are playing because of it, so I made this loop function, does this cause lag or makes game with no lag?

local script:

local distance = 250
while wait(25) do
    for i, v in pairs(game.Workspace:GetDescendants()) do
        if v:IsA("BasePart") and (game.Players.LocalPlayer.Character.HumanoidRootPart.Position - v.Position).magnitude >= distance and v.Name ~= "Baseplate" and not v.Parent:FindFirstChild("Humanoid") then
            v.Transparency = 5
        elseif v:IsA("BasePart") and v.Name ~= "Baseplate" and not v.Parent:FindFirstChild("Humanoid") then
            v.Transparency = 0
        end
    end
end

What it does is, if player is in stage 15, they can only see until 10-20 stages

more than 250 studs = not visible

i thought this can work please tell me

Iterating through an entire game with many parts and changing properties can potentially cause lag. Also, transparency only goes to a max of 1 where 1 is 100%.

1 Like

oh yes, but is there any way to reduce lag, as there are 50k parts in game approx, 25 remote events, 15 server side scripts, 85 workspace models scripts

vehicles, and physics blocks and tween blocks to

I would recommend using FilteringEnabled to reduce the view distance, if that’s what you’re going for. Just note that objects that don’t appear client-side will actually not exist client-side.

ok but its deprecated

do i still have to use it? another way to reduce lag?

Sorry, I mixed it up with the wrong thing. The property I meant is StreamingEnabled.