Binding a function without passing parameters to function

I’m trying to use :Connect to bind a RBXScriptSignal to a function I use elsewhere in the script, the function looks for a first argument, if one is not provided it uses a template. (Mode or Default_Setting).

Later in the function it uses an if statement on this argument. I’m connecting a button. Activated to the function, but the button passes an inputObject. Meaning I have to bind the button. Activated to a function which calls a function…

Is there anyway around this? Thank you.

function Function(…)
    print(…)
end

Event:Connect(function()
    Function()
end)
function Function(…)
    print(…)
end

Event:Connect(Function)

if you want to pass parameters use the bottom code
if you don’t want to pass parameters use the top code

I was hoping there was some way to bind it without binding a new function, guess not. Thank you.

Use a factory.

local function Touched(sender)
  return function(touchedPart)
    print(sender, "touched", touchedPart)
  end
end

Part.Touched:Connect(Touched(Part))
1 Like