innovolt
(innovolt)
May 10, 2020, 1:13am
#1
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?
123marble
(123marble)
May 10, 2020, 1:22am
#2
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)
innovolt
(innovolt)
May 10, 2020, 1:25am
#3
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
123marble
(123marble)
May 10, 2020, 1:32am
#4
I’m not sure what you mean by ‘override’, do you want to pass into ServerOnRayHit
the parameters from rayHitEvent
too?
innovolt
(innovolt)
May 10, 2020, 1:32am
#5
Yes, I want to pass that + the damage value inside the server
123marble
(123marble)
May 10, 2020, 1:35am
#6
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)
123marble
(123marble)
May 10, 2020, 1:37am
#7
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)
123marble
(123marble)
May 10, 2020, 1:43am
#8
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)
innovolt
(innovolt)
May 10, 2020, 1:44am
#9
It’s a custom raycast so the first argument isn’t the player and OnServerEvent is handled in the module also