Render distance script

would like to know how to make a render distance script that basically, loads things in that are near the player and unloads things far from the player. can’t really find anything useful on here or elsewhere.

1 Like

You may be interested in StreamingEnabled .

However, it can often be better to dynamically load and unload manually through ReplicatedStorage and Workspace.

1 Like

Streaming. Just streaming. You can’t change properties in game unfortunately so you may have to make your own system.

i dont get why you would need this, roblox has its own graphics system that loads in graphics in a way similar to render distance

1 Like

If you do not want to use the content streaming function provided by ROBLOX then your next best bet would be to make your own.

One of the ways you could go about this is getting the distance from the character to the part and if it fits within the restrictions then parent it inside a folder in the workspace otherwise move it somewhere such as server storage

how would i do this for ui? Im trying to render about 10k imagebuttons off the screen and only render the ones players can see. but the checking is whats making the game lag

Assuming you mean billboard gui’s there is already a prebuilt feature in those. Just change the Display distance on them to an applicable distance

It depends how you are checking the distances, some code would help us to see where the lag might be coming from. There are many efficient ways to check objects for distance and tag them as active/inactive. 10k image buttons sounds like an awful lot of buttons to have sat off screen somewhere, if the buttons have similar properties to one another my guess it is a design flaw. Please post some code.

roblox’s streaming system just doesn’t cut it for me

You’re going to need to do it manually, then.
Games like DOORS dynamically load and unload every few rooms to reduce lag, since each room is very detailed.

  • They load in the 2 or 3 rooms ahead of the current room by bringing them into the Workspace from ReplicatedStorage.
  • They unload the the 3rd or 4th room behind the current room by placing them in ReplicatedStorage from Workspace.

Not sure if this applies to you, but perhaps you can do a similar thing but with a Chunk System like in certain games like Minecraft.

for i, frame in pairs(game.CollectionService:GetTagged("Chunk")) do
	local playerhead = frame.Parent.Parent.DragableFrame

	local collectionservice = game:GetService("CollectionService")
	if frame:IsDescendantOf(script.Parent) then
		local id = tostring(frame.Parent.Parent.Parent.Parent.ID.Value..frame.Name) 
		local guiInset = game:GetService("GuiService"):GetGuiInset()


		local function isInScreen()
			local pos = frame.AbsolutePosition + guiInset
			return pos.X + frame.AbsoluteSize.X <= frame.Parent.Parent.AbsolutePosition.X+frame.Parent.Parent.AbsoluteSize.X and pos.X >= -frame.Parent.Parent.AbsoluteSize.X
		end



		frame.Parent.Parent.Octaves.DescendantAdded:Connect(function(child)
			task.wait()
			if not game.CollectionService:HasTag(child,"notes") then return end
			if child.AbsolutePosition.X >= frame.AbsolutePosition.X and child.AbsolutePosition.X <= frame.AbsolutePosition.X+frame.AbsoluteSize.X then

				collectionservice:AddTag(child,id)
				child.assets.Chunk.Value = frame
				if isInScreen()  then
					collectionservice:AddTag(child,"regions")
					child.Visible = true
				else
					collectionservice:RemoveTag(child,"regions")
					child.Visible = false
					child.MakeGUIDraggable.Enabled = false
					child.MakeGUICopyable.Enabled = false
				end	
			end
		end)

		frame.Parent.Parent.Octaves.DescendantRemoving:Connect(function(child)
			if not game.CollectionService:HasTag(child,"notes") then return end
			if child.AbsolutePosition.X >= frame.AbsolutePosition.X and child.AbsolutePosition.X <= frame.AbsolutePosition.X+frame.AbsoluteSize.X then
				collectionservice:RemoveTag(child,id)
			end
		end)

		frame.Parent.Parent:GetPropertyChangedSignal("CanvasPosition"):Connect(function()
			wait()
			if isInScreen()  then
				if frame.rendered.Value == true then return end
				frame.rendered.Value = true
				frame.BackgroundColor3 = Color3.new(1, 1, 1)
				for i, v in pairs(collectionservice:GetTagged(id)) do
					collectionservice:AddTag(v,"regions")
					v.Visible = true
				end
			else
				if frame.rendered.Value == false then return end
				frame.rendered.Value = false
				frame.BackgroundColor3 = Color3.new(0.333333, 0.333333, 0.498039)
				for i, v in pairs(collectionservice:GetTagged(id)) do
					collectionservice:RemoveTag(v,"regions")
					v.Visible = false
					v.MakeGUIDraggable.Enabled = false
					v.MakeGUICopyable.Enabled = false
				end
			end
		end)
	end
end