So what I am essentially trying to achieve is making a system that optimizes a scrolling frame so when you scroll with more than 1000 items it won’t lag. I have seen this done with Bubble Gum Simulator where they delete the children inside of the frame when it is not in view while scrolling to reduce the lag while you scroll through the inventory. I have made an attempt but looping through the items just isn’t efficient enough and I’m primarily just stumped on how they achieved smooth scrolling for 4000 pets in the inventory. Here is the code I used to delete the children when they are not in view…
local ReplicatedStorage = game:GetService("ReplicatedStorage")
function collidesWith(gui1, gui2)
local gui1_topLeft = gui1.AbsolutePosition
local gui1_bottomRight = gui1_topLeft + gui1.AbsoluteSize
local gui2_topLeft = gui2.AbsolutePosition
local gui2_bottomRight = gui2_topLeft + gui2.AbsoluteSize
return ((gui1_topLeft.x < gui2_bottomRight.x and gui1_bottomRight.x > gui2_topLeft.x) and (gui1_topLeft.y < gui2_bottomRight.y and gui1_bottomRight.y > gui2_topLeft.y))
end
for i = 1, 4000 do
local clone = script.Template:Clone()
clone.Parent = script.Parent
clone.Name = i
end
script.Parent:GetPropertyChangedSignal("CanvasPosition"):Connect(function()
for i, v in ipairs(script.Parent:GetChildren()) do
if v:IsA("Frame") then
if collidesWith(v, script.Parent) then
if not v:FindFirstChild("Info") then
ReplicatedStorage.Info:Clone().Parent = v
end
else
if v:FindFirstChild("Info") then
v.Info:Destroy()
end
end
end
end
end)
Here you can see that the fps drops when trying to scroll with the code.
https://gyazo.com/00e618e93b7ff2fece571d77dd381e75
Does anybody have a better way of doing this?