Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make my script check and delete only the objectclass "Frame"?

Asked by 5 years ago
--ordertools Folder Contains
--1 UIListLayout
--1 Folder
--2 Frames

local list = script.parent.parent.ordertools:GetChildren()
if list:IsA("Frame") then
list:Destroy()
end
print("hello")
end
end

I'm trying to create a script that detects only frames then deletes them in a specified folder, but I keep running into the following error

attempt to call method 'IsA' (a nil value)

1 answer

Log in to vote
1
Answered by 5 years ago

There are two method you could do what you're trying to do:

The first would be to use FindFirstChildOfClass("Frame"), like so

local frame = script.parent.parent.ordertools:FindFirstChildOfClass("Frame")

if frame then
    print("Frame destroyed")
    frame:Destroy()
else
    print("Frame does not exist")
end

Otherwise you could use a loop, like so

local fold = script.parent.parent.ordertools:GetChildren()

for _,v in pairs(fold) do
    if v:IsA("Frame") then
        v:Destroy()
    end
end

The first option would be if there's only one frame, the second is if there are multiple frames.

The reason your code did not work is because it was trying to see if an array was a frame. When you use GetChildren() it returns an array. If you want to index it you use a loop or you can index it directly.

Your code essentially was doing this: if {Frame, Frame}:IsA("Frame") then

So since you're trying to use IsA() on something that is not an instance it error-ed.

Ad

Answer this question