Render Script is preventing other scripts from functioning

For this Render script there’s a folder in workspace called “Outfits” and it just has roblox avatars inside it and over 3,013 avatars inside. The script works as it’s supposed to as you can tell it’s supposed to only show models in the radius of the player which is does that. There is a proximitypromt script and multiple scripts that do things for the folder in workspace called “Outfits” that for all models inside, there is a button you hold for a avatar purchasing gui that pops up and allows you to purchase the avatar. The issue I came across is sometimes when you join the game the proximityprompt is gone and you no longer can view the model/purchase items, but sometimes when you join it does work, it will also happen on every device. For my final guess of what’s going on is that the render script is preventing the other scripts to load properly for anything for the “Outfits” folder in workspace. Hopefully the two videos of it working and not working for a better example an idea of what’s going on

Working

Not working

local renderRadius = 45 -- Render distance radius
local refreshFrequency = 10 -- Amount of frames to wait before checking the distance of objects

local renderFolder = Instance.new("Folder", game:GetService("ReplicatedStorage"))
renderFolder.Name = "RenderCache"
local localchar = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local localhrp = localchar:WaitForChild("HumanoidRootPart")

local treeParts = {}
for i,object in pairs(workspace.Outfits:GetChildren()) do
    if object:IsA("Model") then
        table.insert(treeParts,object)
        object.Parent = renderFolder
    end
end

local irfs=0
local function updateRender()
    irfs=irfs+1
    if irfs>=refreshFrequency then
        irfs=0
        if localhrp then
            for i,v in pairs(treeParts) do
                local startPart = v:FindFirstChildWhichIsA("BasePart")
                if startPart then
                    local partDistRender = (startPart.CFrame.p-localhrp.CFrame.p).magnitude
                    if partDistRender>renderRadius then
                        if v.Parent==workspace then
                            v.Parent=renderFolder
                        end
                    else
                        if v.Parent==renderFolder then
                            v.Parent=workspace
                        end
                    end
                end
            end
        end
    end
end

game:GetService("RunService"):BindToRenderStep("RenderSys", 1, updateRender)

I believe the underlying issue here is that you have 3,013 avatars. I have no idea how you’ve structured your proximity prompt script but assuming that you are using that singular script to handle all proximity prompts, you can see how the sheer number of avatars can overwhelm it to where it stops working, as you say in your post, or (most likely) throws out a Script Timeout error. Consider using just a few hundred avatars to test if the issue remains before trying out other solutions as that may very well be the problem here (and if so, you may need to reconsider your approach with handling these proximity prompts).

1 Like