Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does the value of my spare ammo not change even if I hold my gun while walking over the object?

Asked by 6 years ago
Edited 6 years ago

I made a block that has the script as a child of that block and it does delete the block but my value for spare ammo does not change?

local giveAmmo = 14
script.Parent.Touched:connect(function(hit)
    if game.Players:GetPlayerFromCharacter(hit.Parent) then
        hit.Parent.Handgun.SpareAmmo.Value = hit.Parent.Handgun.SpareAmmo.Value + giveAmmo
        script.Parent:Destroy()
    end
end)

P.S. The "SpareAmmo" is an "int value" that I input into the gun and the gun works perfectly well.

ExtraAmmo = script.Parent.SpareAmmo.Value
local function Reload()
    if not Reloading then
        Reloading = true
        if AmmoInClip ~= ClipSize and SpareAmmo > 0 then
            if RecoilTrack then
                RecoilTrack:Stop()
            end
            if WeaponGui and WeaponGui:FindFirstChild('Crosshair') then
                if WeaponGui.Crosshair:FindFirstChild('ReloadingLabel') then
                    WeaponGui.Crosshair.ReloadingLabel.Visible = true
                end
            end
            if ReloadTrack then
                ReloadTrack:Play()
            end
            script.Parent.Handle.Reload:Play()
            wait(ReloadTime)
            local ammoToUse = math.min(ClipSize - AmmoInClip, ExtraAmmo)
            AmmoInClip = AmmoInClip + ammoToUse
            ExtraAmmo = ExtraAmmo - ammoToUse
            UpdateAmmo(AmmoInClip)
            if ReloadTrack then
                ReloadTrack:Stop()
            end
        end
        Reloading = false
    end
end

And this is the reloading part of the script if you guys need it.

0
Is it not changing at all or is the gun not reconizing that it changed? Scubadoo2 115 — 6y

Answer this question