Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

LoD render distance script doesn't work?

Asked by 6 years ago
RunService:BindToRenderStep("Performance", 1, function()

    for _,v in pairs(Camera:GetChildren()) do
        if v:IsA("Part") or v:IsA("MeshPart") then
            local distance = Player:DistanceFromCharacter(v.Position)
            if distance >= game.Lighting.FogEnd+750 then
                v:Destroy()
            end
        end
    end

    for _,v in pairs(LocalParts:GetChildren()) do
        if v:IsA("Part") or v:IsA("MeshPart") then
            local distance = Player:DistanceFromCharacter(v.Position)
            if distance < game.Lighting.FogEnd+750 then
                for _,g in pairs(Camera:GetChildren()) do
                    if g.Position == v.Position then
                        return
                    end
                end
                v:Clone().Parent = Camera
            end
        end
    end

end)

This script seems to stop cooperating after one frame's worth of loading. It works, but it returns end if even a single meshpart or part is in the place it's supposed to be, regardless of where you as the player are. Like. When you spawn in, it's fine, but if you wander off into the distance, you'll reach the end of the rendering and find just barren wasteland where stuff should be, until you're out of range of the last object. It'll then delete and the script will run once again... for a single frame. Lather rinse repeat. I'm not sure what to do?

Note: The parts being removed at a distance are fine. That works perfectly. It's the chunk of code where the parts need to load in that's giving me problems.

Answer this question