✓ Accepted answer
Your script in correlation to your question title is somewhat confusing so I will just go according to your title. Otherwise if you're not deleting individual GUI objects, just delete the entire frame its in instead. So to answer your question:
Assume playerlist is defined so in your case I will assume is:
local playerlistFrame = script.Parent.Frame
Now there are two methods to doing this depending on your use case. If you are simply removing everything inside of it as in their children which is only the hierarchy below the frame:
for _, v in pairs(playerlistFrame:GetChildren()) do
v:Destroy()
end
If you are only targeting GUI then you will need to use an if statement since it will target all children including scripts and UI constraints. To do that with the if statement you can search for the class "GuiObject".
for _, v in pairs(playerlistFrame:GetChildren()) do
if v:IsA("GuiObject") then
v:Destroy()
end
end
The second method, if you have more than just children and those children have children as well, you can use :GetDescendants() which removes entirely everything inside it. You can just replace GetChildren() with GetDescendants() and that's it.
for _, v in pairs(playerlistFrame:GetDescendants()) do
if v:IsA("GuiObject") then
v:Destroy()
end
end
Since I am assuming you don't know about placeholder variables as you have a unused i variable, you can use the underscore _ to replace useless variables in the pairs loop. For example in your script, I would replace i with _ since you won't use i.
Note: In this use case, pairs or ipairs does not matter by choice but will matter in different scenarios, usually involving tables.
2 comments
Mhm. I'm actually new to LUA and I'm still learning! Thank you so much it's working now :D
No problem.