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?