Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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.

4 comments

0

maybe try if not obj.ClassName=="Script"

0

Just to be clear the, other "part" is a different part. I don't want to reveal my code.

0

Pretty sure that you shouldn't store things inside of parts. They should be under a model,

0

check if the object is there

1 answer

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

2 comments

0

I just noticed their were brackets.

0

This solution didn't work.

This discussion is preserved as it was. New answers, comments, and votes are closed.