So I’ve been working on this gun system that has a bug that I’ve never encountered before. If two players are in the server, They share the same exact ammo values.
Some things to note:
- This is happening on the SERVER. This is not an issue with GUI
- The script is located in the tool itself. So no shenanigans with it being in ServerScriptService
- Values use variables instead of IntValues
Heres the reloading code:
if reloading then return end
local ammoAllowed = ammo + 2 -- Ammo amount that allows them to shoot again, If this exceeds the max then it will just let them shoot at the max
if shooting == false then
if ammo < maxAmmo then
if equipped == true then
local char = script.Parent.Parent
local plr = game.Players:GetPlayerFromCharacter(char)
task.wait(1)
reloading = true
canShoot = false
while ammo < maxAmmo and reloading == true do
if reserve == 0 then break end
ammo += 1
reserve -= 1
print(plr.Name.." has "..ammo.." ammo and "..reserve.." reserve ammo")
ammoEvent:FireClient(plr, ammo, reserve)
if ammo == ammoAllowed then
canShoot = true
end
if ammo == maxAmmo then
reloading = false
canShoot = true
end
task.wait(0.5)
end -- End of while loop
end
end
end
If you can help with this issue, I’d really appreciate it. Also, If this code is messy or does something inefficently, Please let me know. Ty <3