Hello, so i was wondering if I were to make a rendering system where it would load the nearest items how would I do that correctly. Would I keep the items in replicated storage then move them out once close enough because streaming enabled doesn’t really help much with a map that’s all part terrain. I noticed South West Florida has a rendering system like that and I just need ideas on how it could possibly work.
Just do something along the lines of:
local RunService = game:GetService("RunService")
local LocalPlayer = game:GetService("Players").LocalPlayer
local character = LocalPlayer.Character or LocalPlayer CharacterAdded:Wait()
local hrp = character:WaitForChild("HumanoidRootPart")
local markersFolder = workspace:WaitForChild("RenderMarkers")
local proxies = {}
for _, marker in pairs(markersFolder:GetChildren()) do
if marker:IsA("BasePart") then
table.insert(proxies, {
Part = marker,
Loaded = false,
ObjectID = marker:GetAttribute("ObjectID"),
Radius = marker:GetAttribute("BoundingRadius") or 100
})
end
end
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RenderableAssets = ReplicatedStorage:WaitForChild("RenderableAssets")
RunService.RenderStepped:Connect(function()
for _, proxy in ipairs(proxies) do
if not proxy.Loaded then
local distance = (hrp.Position - proxy.Part.Position).Magnitude
if distance < proxy.Radius then
local asset = RenderableAssets:FindFirstChild(proxy.ObjectID)
if asset then
local clone = asset:Clone()
clone:SetPrimaryPartCFrame(proxy.Part.CFrame)
clone.Parent = workspace
proxy.Loaded = true
proxy.RenderedObject = clone
end
end
else
local distance = (hrp.Position - proxy.Part.Position).Magnitude
if distance > proxy.Radius + 50 then -- buffer to avoid constant reloads
if proxy.RenderedObject then
proxy.RenderedObject:Destroy()
proxy.RenderedObject = nil
end
proxy.Loaded = false
end
end
end
end)
Wouldnt that cause lag issues you think if you load too much in at a time?
Instead of immediately loading it you can make use of queuing before loading it, so you call a function which puts it in a table. Then every tick (frame) you load a couple of models etc. You can also remove them from the queue and so on.