Proper reloading system

I’ve tried many calculations but still broken
Example:
When i have
9/10
9 out of 10 ammo
and when i reload it needs to be set to
10/9
and another ex:
2/3
reloads to
5/0
Cant seem to get it to work. this is what im working with

local weaponAmmo = self.ammoInWeaponValue
			local MaxAmmo = self.instance.Configuration.MaxAmmo
			local LeftInMagazine = self.instance.Configuration.AmmoCapacity
			local older = self.instance.Configuration.AmmoCapacity
			local cl = older.Value - MaxAmmo.Value
			
			LeftInMagazine.Value =  cl
			weaponAmmo.Value =  MaxAmmo.Value

currently just sets it to 0

1 Like
local weaponAmmo = self.ammoInWeaponValue
local MaxAmmo = self.instance.Configuration.MaxAmmo
local LeftInMagazine = self.instance.Configuration.AmmoCapacity

local reloadedAmmo = math.clamp(MaxAmmo.Value - weaponAmmo, 0, LeftInMagazine.Value)

weaponAmmo.Value += reloadedAmmo
LeftInMagazine.Value -= reloadedAmmo
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.