Hello, so I’ve been trying to make a decent and performant gun system the past month and a half, however I’ve been running into issues that I think have to do with exploiting.
Currently, the ammo system for my weapons is handled on the server through a Remote Function event where the player clicks R on a local script, then a remote function is fired to the server to replenish the ammo on the server, then it returns back to the client to replenish the ammo there as well. If that was confusing, here is how it is done:
This is on the Client:
if aN == "Reload" and iS == Enum.UserInputState.Begin then
if Ammo < MaxAmmo then
CAS:UnbindAction("ARShot")
CAS:UnbindAction("Reload")
firing = false
Reloading = true
AmmoCounter.Text = "Reloading..."
local Reloaded = Reloader:InvokeServer(Ammo)
if Reloaded then
Ammo = MaxAmmo
Reloading = false
CAS:BindAction("Reload", Reload, false, Enum.KeyCode.R, Enum.KeyCode.ButtonX)
CAS:BindAction("ARShot", AR, false, Enum.UserInputType.MouseButton1, Enum.KeyCode.ButtonR2)
AmmoCounter.Text = "Ammo: ".. Ammo .."/".. MaxAmmo
end
elseif Ammo == MaxAmmo then
return
end
end
end
This is on the server with the first being the reload function, and the second being the ServerInvoke:
function Reload()
if Ammo == 0 then
Reloading = true
task.wait(2)
Ammo = MaxAmmo
Reloading = false
elseif Ammo <= MaxAmmo then
Reloading = true
task.wait(2)
Ammo = MaxAmmo
Reloading = false
end
end
Reloader.OnServerInvoke = function(plr)
local ReloadSuccess = false
print(Ammo)
Reload()
task.wait(2)
local ReloadSuccess = true
return ReloadSuccess
end
Now my real issue is; Do I actually have to go through all of this? Or can I just make the Ammo completely client sided. When the player dies as they reload or unequip the weapon, the reload system tends to bug or shoot an error, and due to my inexperience with client-server communication in this form of context, I don’t know what I should do. I don’t want hackers/exploiters to change the ammo count of their weapon and fire infinitely.
Also, I change an ammo count on the client for the AmmoCounter and to make sure the gun also doesn’t fire when the ammo is 0 on the client aswell.
TL; DR: I change ammo on the server to prevent hackers; Is it really necessary?
