What is the best way to handle raycasting for a gun tool?
What is the best way to handle raycasting for guns so remote events aren't spammed and raycast is visible to everyone? The chunk of code I have made regarding firing the gun is below. Please read bottom of post before answering!
01 | Vulcan.Equipped:Connect( function (mouse) |
02 | UserInputService.InputBegan:Connect( function (ShootKey) |
03 | if ShootKey.UserInputType = = Enum.UserInputType.MouseButton 1 then |
04 | GunFire:FireServer( true ) |
07 | UserInputService.InputEnded:Connect( function (StopShootKey) |
08 | if StopShootKey.UserInputType = = Enum.UserInputType.MouseButton 1 then |
09 | GunFire:FireServer( false ) |
13 | ConnectM 6 D:FireServer(Vulcan.BodyAttach) |
14 | char [ "Right Arm" ] .GunMotor 6 D.Part 0 = char [ "Right Arm" ] |
15 | char [ "Right Arm" ] .GunMotor 6 D.Part 1 = Vulcan.BodyAttach |
Above is my current code in localscript.
Below is my server script.
1 | VulcanEvent:WaitForChild( "GunFire" ).OnServerEvent:Connect( function (plr, CanFire) |
Neither gives an error and both are doing what they should. This would work fine for singleplayer, but in multiplayer, everyone hold-clicking will be able to fire the event therefore messing up the trues and falses for everyone. How would you handle raycasts for a gun while keeping remote event spamming to a minimum and with minimal chances of messing up the true/false for each player? For context, this is for a gun clan fort and most likely, everyone in the server will be using said guns most of the time. Apologies if my explanations are unclear, let me know if I don't make sense and I'll rephrase.