IsA() not working properly

Howdy,

I am using this lil script where it checks if an object is a ClickDetector:

local click = weap:GetDescendants()

if click:IsA("ClickDetector") then

However, I keep getting this error message:

ServerScriptService.Click:5: attempt to call a nil value

I thought it was an error with the GetDescendants() part, although changing it did nothing. Any suggestions?

:GetDescendants() returns a table, which is not an instance. What you probably meant to do was

local click = weap:GetDescendants();
for _, v in next, click do
    if v:IsA("ClickDetector") then
        --do something
    end
end

You need a for loop for that, shown above this message

Cheers buddy! Helped and it worked!

1 Like