How do I pass a parameter within an event connection?

A generic example of what I am trying to do is the following:

function onHit(injectedParam, part)
end

injectedParam = "Hello"
touchablePart.Touched:Connect(onHit(injectedParam))

In the above, I realize that part is automatically send to hit, and I am trying to add the extra parameter. In the code below, you can apply that contextually to my actual code.

-- This is what I have:

-- Function
function OnRayTerminated(self, cast)
end

-- Event Connection
self._maid:GiveTask(self.Caster.CastTerminating:Connect(function () OnRayTerminated(self) end))

With this code in place, cast in the function return nil. The event sends the parameters cast and I am trying to add self as a sent parameter.

I am aware I can add OnRayTerminated to my class which will inherit self but I don’t really want to due to the nature of the code; however, I can if I have to.

self._maid:GiveTask(self.Caster.CastTerminating:Connect(function (…) OnRayTerminated(self, …) end)

Pardon the succinctness, I’m on mobile. The … Is literal, don’t change it. Let me know if you have more questions.

1 Like

That’s what I was thinking, but my IDE and Linter (Visual Studio Code and some Roblox/Luau linters) were flagging the … saying it was only for variadic functions. I never just tested it with it. I’m also on mobile now, I’ll try it and see what happens. I also didn’t have … in the first function () only the function call. I’ll try it in the morning.

1 Like

Would this not work?

self._maid:GiveTask(self.Caster.CastTerminating:Connect(function (cast) OnRayTerminated(self, cast) end))
1 Like

I was thinking something like this, but forgot the in the function called by connect.
Thank you for pointing this out. I have tested this and it is working properly.

1 Like

This also worked, but due to @JarodOfOrbiter being first, I have marked his as the solution. Than you for your help!