Is this script bad for performance?

Hi, I found a yt vid for a draw distance script. Here is the script:
However I am unsure if it would be bad for performance as I would have over 1000 different objects in this “Draw distance folder”

The script:

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Workspace = game:GetService("Workspace")
local RunSerivce = game:GetService("RunService")

local LocalPlayer = Players.LocalPlayer

local RenderCache = ReplicatedStorage:WaitForChild("RenderCache")

local Character = script.Parent

local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

local RenderDistance = 900

local Render = Workspace:WaitForChild("Draw_Distance")

local Parts = {}


function Scan()
	for _, Object in  next, Render:GetChildren() do
		table.insert(Parts, Object)
		Object.Parent = RenderCache
	end
end

function GetPart (Object)
	if (Object:IsA("BasePart")) then
		return Object
	else
		for _, Obj in next, Object:GetChildren() do
			return GetPart(Obj)
		end
	end	
	return nil
end


function Update()

	for _, v in next, Parts do
		local Part = GetPart(v)


		if (Part) then
			local Distance = (Part.CFrame.p - HumanoidRootPart.CFrame.p).Magnitude

			Distance = math.floor(Distance + 0.5)

			if (Distance <= RenderDistance) then
				v.Parent = Render
			else
				v.Parent = RenderCache
			end
		end
	end
end

Scan()
RunSerivce:BindToRenderStep("RenderSys", 1, Update)

Let me know if I can do anything to make it better for performance or if it isn’t bad for performance.
Cheers,

1 Like

Draw distance? why don’t you just use StreamingEnabled.

1 Like

It doesn’t dynamically update and I can’t choose what I want streamed or not

1 Like

This function isn’t performant at all for such task as it will give the sense of freezing when you get to have like a bunch of parts (to fix this you will have to yield every 20 objects). I also recommend is connected to Hearbeat instead of BindToRenderStep.

I do want Roblox to add a RenderDistance property to objects, but I can’t post at all in the Engine-Feature channel.

@FentTamer StreamingEnabled is nothing like the RenderDistance. Idk how can people still confuse them knowing that when we say render distance, is by the Engine just not rendering certain objects. Not StreamingEnabled that will literally just send to the client certain data when they are near by.

In Roblox currently if you have a forest with like 1k trees, the engine will render each single tree. No way to go around this other than enabling the StreamingEnabled feature which is nothing like rendering distance (which is what I am requesting) and parenting objects using lua is also very inefficient.

1 Like

Agreed. If they do add render distance. I’d like to be able to customise what disappears or not too.
Thanks for the reply

1 Like