How to change weapon damage using FastCast Module?

Currently I have this code that deals damage once the ray casted by FastCast hits a player’s character (on server)

local function RayHit(cast, result, valocity, bullet)
	local Hit = result.Instance
	if Hit.ClassName == "MeshPart" or Hit.Name == "HumanoidRootPart" then
		Hit.Parent.Humanoid.Health -= 10
	end
end

NewRay.RayHit:Connect(RayHit)

But I have a problem that I don’t know how I would tell this function to deal a certain amount of damage based on the gun that the player is using.

Previously, with other gun systems that don’t use FastCast, I have done this by passing a weapon name variable to the server, checking whether the player actually holds this weapon and then the shooting functions would change their Damage, Range, Firerate and Ammo by finding this data in a table using the weapon name variable.

Example:

--Client
RemoteEvent:FireServer(WeaponName)

--Server
local Table {Weapon1 = {Damage = 10, Range = 100}, Weapon2 = {......}}

RemoteEvent.OnServerEvent:Connect(function(WeaponName)
     local Damage = Table[WeaponName].Damage
     local WeaponRange = Table[WeaponName].Range
--etc......
end)

However, now that the RayHit is a separate function from the shooting function I don’t know how would I pass this weapon name variable.

I guess there are some additional things to FastCast that would help with that?

1 Like

Bumping this to hopefully get a solution

Are you using a single Server script to control all guns? The demo gun I have uses a single Server script per weapon instance, so all variables for defined solely for that weapon, ie:
image

I have one client FastCast script and server FastCast script. The client script would make all the effects and the server deals damage based on the ray the server it casted. I just don’t want to have a FastCast script for every single gun.

For example, I also have guns that don’t use FastCast (they don’t have bullet drop so they just cast a straight ray from point A to B), and I am using one function that takes into account which weapon is the user is holding (via storing gun parameters in a table) Thus, I assume this might also be possible with FastCast?

I would add a “Configuration” item to each weapon, then add Attributes for the required weapon properties like damage, fire rate, spread, etc:
image