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

How to connect a onEquip event to a function?

Asked by
KenzaXI 166
9 years ago

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

Log in to vote
0
Answered by
Discern 1007 Moderation Voter
9 years ago

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!

0
Oh, I thought the Way I wanted was a faster way, thanks! KenzaXI 166 — 9y
0
They both do the exact same thing. One just takes up less lines. Discern 1007 — 9y
Ad

Answer this question