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

Attempt to index nil with "IsA"?

Asked by 3 years ago

Hello, I'm trying to make a script that when you hit a part named "Vetro" the part destroys. I'm doing it serverside.

I get the error "Attempt to index nil with "IsA"?" and I don't understand why I can't fix it.

Take note that that's a RemoteEvent, that's why I've put the if statement.

ServerSide script:

if t == "w" then
        local function vetro(hitted)
            if hitted:IsA("BasePart") and hitted.Name == "Vetro" and hitted.Transparency > 0 then
                hitted:Destroy()
            end
        end
        vetro()
    end

ClientSide script part:

function vetro()
    script.Parent.Event:FireServer("w")
end

I've also tried changing "IsA" with ClassName but still getting an error. Can someone help me please?

0
You need to pass something to the function Soban06 410 — 3y
0
what do you mean? Gabrix23 6 — 3y
0
On line 7, you need to pass something to the function. The object that hitted. Soban06 410 — 3y
0
I've tried putting hitted but always the same. Gabrix23 6 — 3y
View all comments (2 more)
0
im not sure if its supposed to be this exactly but i thought IsA is supposed to go with in pairs loop 3wdo 198 — 3y
0
It does not. The error also means that "Hitted" doesn't exist, you never passed any BasePart into "vetro". Ziffixture 6913 — 3y

1 answer

Log in to vote
0
Answered by
sayer80 457 Moderation Voter
3 years ago
if t == "w" then
        local function vetro(hitted)
            if typeof(hitted) == "Instance" and hitted:IsA("BasePart") and hitted.Name == "Vetro" and hitted.Transparency > 0 then
                hitted:Destroy()
            end
        end
        vetro()
    end

I've added typeof() to check if it is an Instance and not a string. May help

0
getting "attempt to index nil with 'Name'." Gabrix23 6 — 3y
0
that's what I get whenever I hit a part https://gyazo.com/81762c97b4a81704a278b8f459dbe0a8 Gabrix23 6 — 3y
Ad

Answer this question