Still have questions? Join our Discord server and get real time help.
0

# All player's lose ammo when one player shoots a gun?

Edited 4 days ago

I'm trying to make a gun, everything works how I want it to despite the fact that ammo is shared among all players. This includes reloading, I am unsure of why this is happening since the defined objects are within the player's own tool and not everyone else's tools. If anyone could help it would help me a lot, I can't find a way to get past this.

Reload local script snippet (I don't believe this causes any issues) :

--UIS refers to User Input Service
UIS.InputBegan:connect(function(inputObject, gameProcessedEvent)
if equipped == true then
if inputObject.KeyCode == Enum.KeyCode.R then
end
end
end)


CurrentAmmo is a value in the gun that records the amount of value inside the gun.

MaxAmmo is a defined value inside the script. (Not in the gun)

Reload server script snippet (I think the issue is in here somewhere) :

game.ReplicatedStorage.Reload.OnServerEvent:Connect(function(player,MaxAmmo,removem,loadm,loadgun,CurrentAmmo,removemb,loadmb,loadgunb)
--A part in here is left out simply because it is just a randomized sound player, and takes up a lot of space. This only plays sound.
CurrentAmmo.Value = MaxAmmo
CanFireReal = true
CanFire = true
end
end)


Shoot local script snippet:

script.Parent.Activated:Connect(function()
local pos = script.Parent.FirePoint.Position --This updates the position so the bullet's don't appear in a single spot of the map
if game.Players.LocalPlayer.Character.Humanoid.Health ~= 0 then
else
end
end)


Shoot server script snippet:

--I've only showed the part that changes the value since the rest has nothing to do with the values.
if CurrentAmmo.Value ~= 0 then
CurrentAmmo.Value = CurrentAmmo.Value - 1
print(CurrentAmmo.Value)
elseif CurrentAmmo.Value == 1 or CurrentAmmo.Value == 0 then
CurrentAmmo.Value = 0
CanFireReal = false
end


If anyone can help me that would be a huge help, I've been struggling with this for a while now with no success. Having player's spam reload the gun to avoid other player's shooting them gets annoying (when I test the gun with friends). Shared ammo is also an issue.

If any more of the script needs to be shown for an answer to be given, please let me know and I'll provide that section of the script.

Again, thanks for anyone who can help and have a great day/night.

0
If CurrentAmmo is not localized, then that's probably where your problem is. Each player should have their own CurrentAmmo, and not share just one w/ the server. (I'm assuming CurrentAmmo is a numberValue object).  Psudar 83 — 5d
0
CurrentAmmo is a value inside the player's tool, so it is an object. It is also local, so I don't understand why this is happening. CaptainAlien132 184 — 5d