i want to know if its worth using collection service to save memory. if i have over 10k parts being iterated over constanly, i get lag. but if i put scripts in each instead, it also lags
this is in a render system for ui
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*3 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
for this to work