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

Why is my ammo NumberValue not increasing?

Asked by
rdkv 12
4 years ago
Edited 4 years ago

My M4 should be refilling its ammo by adding 100 rounds into reserve every time I touch a certain block but nothing happens and I receive no errors. I have 'Ammo' and 'StoredAmmo' NumberValues inside the main script of my M4, I would know if I was receiving ammo because I have an ammo GUI that works but no ammo is added.

function onTouched(hit)
    local human = hit.Parent:FindFirstChild("Humanoid")
    local player = game.Players:FindFirstChild(hit.Parent.Name)
    if (human ~= nil) then
        local StoredAmmo = human.Parent.M4A1.Gun_Script.StoredAmmo
        if (StoredAmmo~=nil) then
            StoredAmmo.Value = StoredAmmo.Value + 100
            script.Parent:Destroy()
        end
    end
end

script.Parent.Touched:Connect(onTouched)

Any help is appreciated, not sure how to go about this.

0
Hate to be that guy but those if checks should be debugged and made sure they’re fired. SmartNode 383 — 4y
0
For debugging i always put print commands in different places to get a better idea where the problem is OBenjOne 190 — 4y

Answer this question