I am confused on how should i handle multiple gui events (like Mouse1ButtonDown) i am afraid about memory leak and i will have tons (like +50 ui elemnts) that have this event how do devs handle this ?
You will have to connect a callback to every element for each event. Because there’s no event bubbling, you can’t connect a callback to a parent element and check which children was interacted with. Connecting a single callback won’t produce any memory leak.
i dont understand im thinking about using linked list or collection service but im confused since some of uis have different functions
Yes, you could use CollectionService and there’s no linked list support in lua. 50 elements seem quite a big number for a single UI. Your best option would be to avoid duplicated elements for different views that do the same thing in different contexts.
i have like multiple ui image buttons, and i can use linked list library ? Also other devs have multiple uis like inventory ,shop systrm…ect how can they do such a thing
As far as I know, having to individually bind events to each Instance is just standard practice.
Memory leak is when the system is storing data that won’t ever be used. If the UI is always gonna be there in the game, it’s not called a memory leak. Having to individually bind connections to each Instance is just a necessary evil, unless you can think of a more efficient way of implementing whatever UI you have.
There is a minor optimization you can generally do; reuse the function that you bound to each UI object. This is assuming that each UI Object does the same exact thing when triggered.
local function playSound()
sound123:Play()
end
for _, v in PlayerGui:GetDescendants() do
if v:IsA("GuiButton") then
v.MouseButton1Down:Connect(playSound)
end
end
but for me i would need like 8 ui active at a one time and it increases until lie 42 uis and another ui that would be showed when i clicked on one of these 42 uis would that be considered a massive memory consuming?
You’re worrying too much. Your game would do fine with hundreds of UIs each having their own connections and events. Memory is only an issue if you’re dealing with hundreds of thousands of instances; a typical Roblox game can have that many parts in the workspace.
Just as an example, here’s my project that has hundreds of buttons:
Connections themselves carry little weight. Dont worry about them, unless its a memory leak.
Alright thank you thats totally a relief ![]()
sorry for the late reply
im wondering how many connections u have there and do they have the same functions?
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.