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

Attempt to index nil with "IsA"?

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?

6 comments

0

You need to pass something to the function

0

what do you mean?

0

On line 7, you need to pass something to the function. The object that hitted.

0

I've tried putting hitted but always the same.

0

im not sure if its supposed to be this exactly but i thought IsA is supposed to go with in pairs loop

0

It does not. The error also means that "Hitted" doesn't exist, you never passed any BasePart into "vetro".

1 answer

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

2 comments

0

getting "attempt to index nil with 'Name'."

0

that's what I get whenever I hit a part https://gyazo.com/81762c97b4a81704a278b8f459dbe0a8

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