How to add arguments to a function without overriding default arguments passed by an event?

Hi, I am using the FastCast module for my gun script.

Putting the same function in every script inside the weapons was getting annoying so I decided to store the functions in a modulescript.

Here’s my issue:
1: Server fires a raycast
2: FastCast will fire an event once the ray hits something with the arguments:

rayHitEvent:Fire(hit, point, normal, material, cosmeticBulletObject)

3: Server listens for the event and connects it to a function inside the new modulescript:

Caster.RayHit:Connect(rayfunc.ServerOnRayHit(damage))

4: Server needs to give the modulescript the damage value, but instead of adding to the existing arguments passed by FastCast, it overrides the first argument instead.

How do you add the damage argument to the existing arguments without overriding the first argument instead?

The Connect method can only take a function as an argument. That may look like what you’ve done but, you have actually passed in the result of calling ServerOnRayHit to Connect.

To fix this you can use an anonymous function
e.g.
Caster.RayHit:Connect(function()
rayfunc.ServerOnRayHit(damage))
end)

It still throws the same error as before

18:24:06.587 - ReplicatedStorage.RaycastFunctions:26: attempt to index number with 'Parent'

because it overrides the first argument that was passed by the event

I’m not sure what you mean by ‘override’, do you want to pass into ServerOnRayHit the parameters from rayHitEvent too?

Yes, I want to pass that + the damage value inside the server

You can add the parameters into the anonymous function and the pass them into ServerOnRayHit from there I think.

Caster.RayHit:Connect(function(hit, point, normal, material, cosmeticBulletObject)
    	rayfunc.ServerOnRayHit(hit, point, normal, material, cosmeticBulletObject, damage))
    end)

Actually, now I remember, I think the first argument will be the player, so you probably want something like this.

Caster.RayHit:Connect(function(player, hit, point, normal, material, cosmeticBulletObject)
    	rayfunc.ServerOnRayHit(hit, point, normal, material, cosmeticBulletObject, damage))
    end)

Also, I think you need to use OnServerEvent, not sure though, if it’s working I wouldn’t worry.

Caster.RayHit.OnServerEvent:Connect(function(player, hit, point, normal, material, cosmeticBulletObject)
    	rayfunc.ServerOnRayHit(hit, point, normal, material, cosmeticBulletObject, damage))
    end)

It’s a custom raycast so the first argument isn’t the player and OnServerEvent is handled in the module also