Upon firing any automatic gun, sometimes there will be a short interruption between the shots. This came off as surprising to me, because everything is all handled by client (animations, reserve ammo, mag rounds, etc). The server only does checks such as the gun being equipped, if the person is reloading or not, and fires back to client if everything is fine.
I don’t have any scripts ran in a loop that could slow down the server.
The gun’s script rate can go up to 18 max (this seems to only be the case on high fire rate guns, i still find it weird because the remote is only being fired when necessary and as mentioned before, server only does checks, nothing else)
Side questions:
Would it be more optimal to:
Make 1 remote event for all guns? Or would it cause the event to be dropped if there’s too many guns firing the same remote?
Prior to the question above, would one single script that handles the gun remote events reduce the script rate?
one singe script is probably better for sorting, but could cause potential issues, which is plenty better than using one remote event which has a limit to it i think, just incase it somehow fires way too much.
For high-rate guns, you could handle the shooting logic on the client fully, then periodically validate with the server to check if the player is able to continue firing
(checking ammo, reloading, etc…).
This minimizes server communication and helps avoid minor delays. This approach helps
particularly in situations where every millisecond counts, like high fire-rate weapons.
That’s what I’m already doing for this gun system, there is still issues. Maybe the client is the problem?
This is my function:
local function HeartbeatLoop()
if Equipped then
if Held and Reload.Value == false and Rounds.Value > 0 then
local Now = tick()
if Now - LastFired > Attributes.FireRate then
RemoteEvent:FireServer("Fire", Mouse.Hit.p, Camera.CFrame.Position)
LastFired = Now
end
end
end
end
Also, here’s all of the code related to the gun firing
Server
local function OnFire()
if Equipped.Value == true then
if Ready.Value == true and Debounce == false then
game.ReplicatedStorage.Events.ClientVisualizer:FireAllClients(Handle, "FireEffect", Attributes.CasingType)
RemoteEvent:FireClient(Player, "Fire")
end
end
end
Client code that handles gun firing was shown above your reply.
The only other thing is the function that handles events, the callback with the argument “Fire”, had this piece of code that created visual effects. I moved this piece of code to a separate script which is meant for visualizing effects, but this issue still occurs.
if Argument == "Fire" then
if ScreenGui ~= nil then
if Rounds.Value > 0 then
Rounds.Value -= 1
coroutine.wrap(function()
CreateRay(Mouse.Hit.p, Camera.CFrame.Position)
if InspectTrack ~= nil and InspectTrack.IsPlaying then
InspectTrack:Stop()
end
if EquipTrack ~= nil and EquipTrack.IsPlaying then
EquipTrack:Stop()
end
if Rounds.Value >= 0 then
if Rounds.Value == 0 then
if EmptyTrack ~= nil then
EmptyTrack:Play()
end
if Fire1Track ~= nil then
Fire1Track:Play()
end
else
if Fire1Track ~= nil then
Fire1Track:Play()
end
end
end
end)()
end
end
Based on your code, your problem seems to be that the client has to wait for the server to respond. If high-ping players were to play your game, the delay would be insane. You can test this yourself by setting your ping high on studio from File > Studio Settings > Network > Incoming Replication Lag.
What most games do is that they let the client who fired already visualize, so that they never have to wait for the server to do this. All the server has to do then are checks (enough ammo etc.) and let other clients visualize like you are already doing, except for the player who fired.