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

Why won't this function refill my ammo?

Asked by 4 years ago

I am trying to refill my ammo through a remote event, it seems to find the items in the backpack but it doesn't get past "if backpackItems[i]:FindFirstChild("CanResupply")

Can anyone help out? Thanks!

script.Parent.Resupply.OnServerEvent:connect(function(Player,price)
    print(Player)
    print(price)
    local cash = Player.leaderstats.Cash
    local Mag = (script.Parent.Center.Position-Player.Character.HumanoidRootPart.Position).magnitude
    local humanoid = Player.Character:WaitForChild("Humanoid")
    local backpackItems = Player.Backpack:GetChildren()
    for i = 1,#backpackItems do
        print(backpackItems[i])
        if backpackItems[i]:FindFirstChild("CanResupply") then
            print(backpackItems[i].Name)
            local configs = backpackItems[i]:WaitForChild("Configs")
            local ammo = configs:WaitForChild("Ammo")
            local magSize = configs:WaitForChild("MagSize")
            local reserveAmmo = configs:WaitForChild("ReserveAmmo")
            local maxResAmmo = configs:WaitForChild("MaxResAmmo")
            if Mag <= script.Parent.Range.Value then
                ammo.Value = magSize.Value
                reserveAmmo.Value = maxResAmmo.Value
            end 
        end
    end
end)

1 answer

Log in to vote
0
Answered by 4 years ago

Never mind, this function works. It would be beneficial if I payed attention to caps. The value in the gun was "canResupply", and I asked it to find "CanResupply". Notice how c was capitalized when it shouldn't have been.

0
Nice Friskyman321 121 — 4y
Ad

Answer this question