Hi! So I am creating an Ammo system and it is not functioning correctly. No ammo is being deducted. Here is my code:
function module:CreatePlayer(plr)
local newPlayerFolder = Instance.new("Folder")
newPlayerFolder.Name = plr.UserId
newPlayerFolder.Parent = script.Parent.Players
local newPlayerHealthValue = Instance.new("IntValue")
newPlayerHealthValue.Name = "Health"
newPlayerHealthValue.Value = 100
newPlayerHealthValue.Parent = newPlayerFolder
local newPlayerHealthValue = Instance.new("IntValue")
newPlayerHealthValue.Name = "Primary1Ammo"
newPlayerHealthValue.Value = 31
newPlayerHealthValue.Parent = newPlayerFolder
local newPlayerHealthValue = Instance.new("IntValue")
newPlayerHealthValue.Name = "Primary2Ammo"
newPlayerHealthValue.Value = 8
newPlayerHealthValue.Parent = newPlayerFolder
local newPlayerHealthValue = Instance.new("IntValue")
newPlayerHealthValue.Name = "SecondaryAmmo"
newPlayerHealthValue.Value = 12
newPlayerHealthValue.Parent = newPlayerFolder
print("Player "..plr.Name.."'s folder has been setup! ("..plr.UserId..")")
return true
end
function module:UpdateAmmo(plr, gunType, amount)
print("Updating Ammo (Removing "..amount.." ammo)")
local playerFolder = script.Parent.Players[plr.UserId]
if playerFolder == nil then
print("Invalid Player")
return false
end
if gunType == "prim1" then
local ammo = playerFolder["Primary1Ammo"].Value
ammo -= amount
print("New Ammo: "..ammo)
return ammo
elseif gunType == "prim2" then
local ammo = playerFolder["Primary2Ammo"].Value
ammo -= amount
print("New Ammo: "..ammo)
return ammo
elseif gunType == "second" then
local ammo = playerFolder["SecondaryAmmo"].Value
ammo -= amount
print("New Ammo: "..ammo)
return ammo
end
end