✓ Accepted answer
Unfortunately, returning values from an event callback is possible, but useless.
This is because your callback function is being called by Roblox, who doesn't expect, or simply doesn't care whether you return values or not. It will just discard them.
Upvalues
Thankfully there is a way around this. What you can do instead is use "upvalues". That sounds like a whole new concept, but the truth is you've probably already used them before without knowing what they were called. Upvalues are variables that are declared prior to your function, in an upper scope. For example:
local tool = script.Parent
local selection
tool.Equipped:connect(function(mouse)
local user = tool.Parent
mouse.Button1Down:connect(function()
selection = mouse.Target
end)
end)
game:GetService("UserInputService").InputBegan:connect(function(input, processed)
if not processed then
if input.KeyCode == Enum.KeyCode.Delete or
input.KeyCode == Enum.KeyCode.KeypadPeriod then
if selection and not selection.Locked then
selection:Destroy()
end
end
end
end)
Conclusion
By setting and getting upvalues from within your functions, you can send information around without having to rely on returning values.
Anyway, I hope this helped. If it did then please be sure to accept, and optionally upvote, my answer. It helps both of us. ;) If you need anything else, you need only ask.
2 comments
You can put a variable before you connect the even then assign the value when the event is fired. How / where will this value be used?
Let me get you a full explanation once I'm st my desk