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

"attempt to call a nil value"?

So i was trying to create 2 objects a value and an attachment when clicking certain part, when i tried using this code:

function clicked (playerWhoClicked)
	local startorend = Instance.new("Attachment")
	startorend.Parent = script.Parent
local attachment = Instance.new("NumberValue",workspace.attachments)
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)

It gave me an error "Attempt to connect failed:Passed value is not a function" then when clicking the part nothing would happen except i'd get the error "attempt to call a nil value" If someone could help me i would apreciate. And sorry for bad grammar (i wasnt born in an english speaking country and never did an english scool.

2 comments

1

You connected "onClicked". Your function is "clicked".

0

This is what happens when you copy and paste from roblox wiki...

1 answer

✓ Accepted answer

Your grammar is fine. Like GoldenPhysics said, you need to connect the event to the clicked function. In your code, you are connecting it to onClicked, which doesn't exist in your code. So, the last line of code would look like this:

script.Parent.ClickDetector.MouseClick:connect(clicked)

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