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

How to connect a onEquip event to a function?

Like Title says, but not a script like:

function onEquip
"Blah blah blah"
something.Equipped:connect(onEquip)

But a Script like:

script.Parent.Equipped:connect(function(...

I don't know how to do that, thnaks for the help

1 answer

✓ Accepted answer

What you are trying to create is something called an anonymous function, a function that does not have a direct identifier, or name.

You can only use these kinds of functions with built-in ROBLOX events, such as Equipped or Touched.


yourTool.Equipped:connect(function()
	--Code for when the Tool is equipped.
end)

That would be the same thing as

function onEquipped()
	--Code for when the Tool is equipped.
end

yourTool.Equipped:connect(onEquipped)

But in a less amount of lines.


Here is the Wiki page on anonymous functions so you can read more about them.

If I helped you out, be sure to accept my answer!

2 comments

0

Oh, I thought the Way I wanted was a faster way, thanks!

0

They both do the exact same thing. One just takes up less lines.

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