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

Argument 1 missing or nil? error whenever I run the tool

Asked by 7 years ago
a = script.Parent.Parent.Parent:FindFirstChild(Head)

function a1()
    a:Delete()
end



script.Parent.Parent.Activated:Connect(a1)

Whenever I use the tool i get the error "Argument 1 missing or nil"

It's a tool, It's supposed to remove your head when you use it

Thanks ;P

1
Use :Destroy() not delete! starlebVerse 685 — 7y

2 answers

Log in to vote
0
Answered by 7 years ago

Normally you should tell us not only the error, but what line it occurred on.

metalicurt is correct, you need to have Head in quotes.

However, the script will run before the Tool is parented to the player's character. You should get the head only when the tool is activated or equipped (unless you use game.Players.LocalPlayer.Character)

Also, remember to use descriptive variable names (this is more important in larger scripts). A fixed script:

local tool = script.Parent.Parent

function RemoveHead()
    local head = tool.Parent:FindFirstChild("Head")
    if head then
        head:Destroy()
    end
end

tool.Activated:Connect(RemoveHead)

Note that it checks for the head each time it is activated and won't error if the head isn't there (ex. because the script ran already).

Ad
Log in to vote
0
Answered by 7 years ago

Wouldn't you want the FindFirstChild argument to be a string? as in FindFirstChild("Head")

I am still learning so I may be wrong.

Answer this question