So whenever the player reloads their gun, the script waits until however long it takes to reload, and then it checks if the player unequipped their gun during this time. If they did, then the script doesn’t add ammo to the gun and basically cancels the reload.
The way I track this is with a number, which I increase by 1 every time the gun is unequipped, and then to check if the gun was unequipped while reloading, I check if this number is different than at the start of the reload.
It feels like a hacky solution and I wanted to know if there was a better way to check if the gun was unequipped while reloading.
local UnequipCounter = 0
local function Reload()
ReloadAnimation:Play()
local CurrentUnequipCounter = UnequipCounter
task.delay(ReloadTime, function()
if CurrentUnequipCounter == UnequipCounter then
Ammo = MagazineCapacity
end
end)
end
Tool.Unequipped:Connect(function()
ReloadAnimation:Stop()
UnequipCounter += 1
end)