Hello everyone,
I need help in regarding game optimization. What I need to know is, if there is a way to stop loading rigs depending on distance. Since it is an outfit game, all rigs are loading simultaneously, putting strain on the client/server. There is around 300 rigs around a moderately sized map, and with max render distance, all of them load in, every clothing, accessory etc.
The question is, how would I script an optimized system to load rigs only that are around 50 to 100 meters away (customizable distance etc.), and unloading the rigs that were loaded if I leave, or get too far away from the loaded in ones.
1 Like
You might want to look in to Instance Streaming.
1 Like
How would I do it for a specific thing? Only for “Model” children in a folder, instead of having a 64-128 streaming distance for everything?
I tried it like this, without streaming
local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local outfitsFolder = ReplicatedStorage:WaitForChild("Outfits")
local radius = 10 -- Adjust this as needed
local function updateOutfits()
for _, outfitModel in ipairs(outfitsFolder:GetChildren()) do
local distance = (outfitModel.PrimaryPart.Position - humanoidRootPart.Position)
if distance <= radius then
outfitModel.Parent = character
else
outfitModel.Parent = ReplicatedStorage.OUTFITS
end
end
end
updateOutfits() -- Update outfits initially
local function onPlayerMove()
updateOutfits()
end
humanoidRootPart:GetPropertyChangedSignal("Position"):Connect(onPlayerMove)
Players.LocalPlayer.CharacterAdded:Connect(function(character)
humanoidRootPart = character:WaitForChild("HumanoidRootPart")
updateOutfits()
end)