How can I get a certian type of child?

Im making a shop system with different types of content. (ex: backpacks, knives, etc)
2d8d7e40e73a5515ace6fc90515860c2
This is what the explorer looks like while in game.
f15fe670ea2d7073acd108cdd872fbc7
That is my script. I cant Just Delete all the children because there is a grid layout and a ui padding. Can anyone help me delete only the frames?

use the :IsA() function Instance:IsA

2 Likes

d803c85e25294f727ea2f3c4eb0bce34
Should this work?

No, you need to format it like this

local function removeContent()
    local items = itemsFrame:GetChildren()
    for i = 1, #items do
if items[i]:IsA("Frame") then
 items[i]:Destroy()
end
end
1 Like
for _, Child in ipairs(Parent:GetChildren()) do
	if Child:IsA("Frame") then Child:Destroy() end
end
2 Likes
while itemsFrame:FindFirstChildWhichIsA("Frame") do
 itemsFrame:FindFirstChildWhichIsA("Frame"):Destroy()
end

This may be a little better

local frame = itemsFrame:FindFirstChildWhichIsA("Frame") 
while frame  do
  frame:Destroy()
  frame = itemsFrame:FindFirstChildWhichIsA("Frame") 
end
2 Likes

This is a fairly bad practice and should be avoided, you’re performing the same operation twice (when it isn’t necessary to do so).

2 Likes

Was thinking that after I posted it. A vairable solves the issue but overall not going to cause issues either way.

1 Like