New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Still have questions? Join our Discord server and get real time help.
Log in to vote

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

Asked by 1 year ago
Edited 1 year 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

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

removem, removemb, loadm, loadmb, loadgun, and loadgunb are all sounds.

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

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

    if ReloadDebounce then
    ReloadDebounce = false
    Reloading = true
--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
    Reloading = false
    CanFireReal = true
    CanFire = true
    ReloadDebounce = true

Shoot local script snippet:

    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
        print("Player is dead!")

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
elseif CurrentAmmo.Value == 1 or CurrentAmmo.Value == 0 then
    CurrentAmmo.Value = 0
    CanFireReal = false

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.

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 853 — 1y
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 220 — 1y

Answer this question