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)
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
.