I’ve been working on a gun system since last week and I recently rearranged my code to have effects done on the client and have the server go through validating the player’s shots.
Now, I’m trying to think of how to save ammo on the client as well as the server to add more protection. Right now, I keep track of ammo on the client as well as the logic to reloading. I use attributes to save the gun’s ammo locally.
I’ve looked at threads in the forum and stumbled across this one and that one. Both talked about how the ammo should be saved on the client and on the server, but also how the client should not pass any of its ammo data to the server and instead have the server send information back to the client to adjust its ammo.
This confuses me because I have everything kept on the client right now, so I’m having trouble on what to move around or what to add or remove to make this work in a secure way. (Would I need any remotes? Should I reload on the server? Should I save ammo data on the server and pass data to the client?) Any help would be appreciated!
local ammo = gun:GetAttribute("CurrentAmmo") local ammoReserve = gun:GetAttribute("CurrentAmmoReserve") -- Used every time the player shoots or reloads or drops the gun local function updateAmmo() gun:SetAttribute("CurrentAmmo",ammo) gun:SetAttribute("CurrentAmmoReserve",ammoReserve) end local function fire() local character = player.Character or player.CharacterAdded:wait() if gun.Enabled and not isReloading and character then -- Checks if ammo > 0 then gun.Enabled = false -- Raycast and remote fire to server ammo -= 1 updateAmmo() -- Effects wait(FIRE_RATE) gun.Enabled = true else clickSound:Play() end end end local function reload() isReloading = true -- Sounds and animations reloadAmmo() updateAmmo() -- Gui updates isReloading = false end