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

What does this mean?

Asked by 8 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

So I made a script to move a part to a different place, but it comes up with "attempt to call a nil value". What does this mean and where does it come from???

function onClick(mouse)
    local character = game.Workspace.Model.Stage1.L
    if character and character:findFirstChild("Humanoid") then
        local b = Instance.new("BodyPosition")
        b.position = Vector3.new(43.65, 5.2, 57.4)
        b.maxForce = Vector3.new(500000000, 500000000, 500000000)
        b.Parent = character.L
        wait(3)
        b.Parent = nil
    end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
8 years ago

It's an annoying bug that this error doesn't tell you where it's coming from.


However, in this case, Script Analysis will warn you of this -- use Script Analysis! Warnings aren't there to be annoying!

You are giving onClicked to MouseClick:connect. But onClicked was never defined, so it is nil.

You meant to write onClick.

Use Script Analysis! Blue underlines mean there is a problem!


As Decemus said, you should use .Position instead of .position and .MaxForce instead of .maxForce. These properties were recently "fixed" to have the correct capitalization available.

Also, b:Destroy() is recommended over b.Parent = nil.

Ad

Answer this question