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

Why does :IsA() throw an error???(attempt to index a nil value)**FIXED**

Asked by
552557 20
5 years ago
Edited 5 years ago

This is the specific part of code that is throwing the error:

for _, obj in pairs(part:GetChildren()) do
    if not obj:IsA("Script") and not obj:IsA("Folder") then
        obj:Clone().Parent = part
    end
end

Whenever I do:

for _, obj in pairs(part:GetChildren()) do
    if obj:IsA("Script")  then
        obj:Clone().Parent = part
    end
end

No errors occur.

0
maybe try if not obj.ClassName=="Script" Zendaya774isstupid 50 — 5y
0
Just to be clear the, other "part" is a different part. I don't want to reveal my code. 552557 20 — 5y
0
Pretty sure that you shouldn't store things inside of parts. They should be under a model, xXDoneBeingCoolXx 33 — 5y
0
check if the object is there Zigzagzones 0 — 3y

1 answer

Log in to vote
-1
Answered by
seith14 206 Moderation Voter
5 years ago
Edited 5 years ago

Use ClassName Instead of IsA. IsA brings back a whole class set, while ClassName selects a certain class.

for _, obj in pairs(part:GetChildren()) do
    if obj.ClassName ~="Script" and obj.ClassName ~="Folder" then
        obj:Clone().Parent = part
    end
end

Then

for _, obj in pairs(part:GetChildren()) do
    if obj.ClassName =="Script"  then
        obj:Clone().Parent = part
    end
end

IsA Examples: http://wiki.roblox.com/index.php?title=API:Class/Instance/IsA

0
I just noticed their were brackets. seith14 206 — 5y
0
This solution didn't work. 552557 20 — 5y
Ad

Answer this question