Weird reload bug?

Sometimes, for a peculiar reason my reload mechanic goes off when it isn’t supposed to. It says the ammo is 0 on the server but in reality, it’s any other number than 0. I’ve tried adding 16 to the ammo instead of setting the ammo to 16 but no avail. It is an incredibly weird bug that I have no other solutions for.

Client script:

local rt = game:GetService("ReplicatedStorage"):WaitForChild("Shoot")
local tool = script.Parent
local mouse = game.Players.LocalPlayer:GetMouse()
local plr = game:GetService("Players").LocalPlayer
local tool = script.Parent
local playergui = plr.PlayerGui
local debounce = false
local char = plr.CharacterAdded:Wait()
local ammo_out = false
local rt = game.ReplicatedStorage.Shoot
local ammo = 16
tool.Equipped:Connect(function()
	screengui1 = game.ReplicatedStorage.AmmoGui:Clone()
	screengui1.Parent = playergui
	screengui1.Enabled = true
	text = screengui1.Frame.Ammo
end)
tool.Unequipped:Connect(function()
	screengui1.Enabled = false
end)

tool.Activated:Connect(function()
	if debounce == false and ammo_out == false then
	print("aa")
	rt:FireServer(mouse.Hit.Position, script.Parent)
	ammo -=1
	text.Text = ammo .. "/16"
		print("sent")
		if ammo == 0 then
			ammo_out = true
			text.Text = "Reloading..."
			task.wait(2)
			ammo_out = false
			text.Text = "16/16"
			ammo = 16
		end
		debounce = true
		task.wait(0.5)
		debounce = false
		end
	end)

Server Script:

local rt = game:GetService("ReplicatedStorage"):WaitForChild("Shoot")
local debris = game:GetService("Debris")
local gunshot = game:GetService("SoundService"):WaitForChild("Gun Shot")
local debounce = false
local ammo = 16
local ammo_out = false
local firerate = 0.5
		local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://13112812781"
local damage = 10
local reload = game.SoundService["Pistol Reload Sound"]
rt.OnServerEvent:Connect(function(plr, mouse, tool)
	local char = plr.Character
	local hum = char.Humanoid
	local animator = hum.Animator
	local effect = tool.Effect.MuzzleEffect
	if tool.Name == "Gun" then


		local debounce2 = false
		if debounce == false and ammo_out == false then
			local loadanim = animator:LoadAnimation(animation)
			loadanim:Play()
			gunshot:Play()
			print(mouse)
			local bullet = Instance.new("Part")
			bullet.Size = Vector3.new(1,1,1)
			bullet.Position = mouse
			bullet.Transparency = 1
			bullet.CanCollide = true
			bullet.Parent = workspace
			ammo -=1
			print(tostring(ammo))
			bullet.Touched:Connect(function(hit)
				print("hit")
				if hit.Parent:FindFirstChild("Humanoid") then
					warn("hum")
					if debounce2 == false then
						if hit.Parent.Name == plr.Character.Name then return end
						hit.Parent.Humanoid:TakeDamage(damage)
						print("wow")
						debounce2 = true
					end
				else
					warn("no hum")
				end
			end)

			debris:AddItem(bullet, firerate)
			effect.Enabled = true
			if ammo == 0 then
				local reloadanim = Instance.new("Animation")
				reloadanim.AnimationId = "rbxassetid://13133924759"
				reloadanim.Parent = script
				ammo_out = true
				local loadanim = char.Humanoid.Animator:LoadAnimation(reloadanim)
				reload:Play()
				loadanim:Play()
				effect.Enabled = false
				task.wait(2)
				ammo += 16
				reload:Stop()
				reloadanim:Destroy()
				ammo_out = false
			end
			debounce = true

			print("debounce1")
			task.wait(firerate)
			debounce = false
			effect.Enabled = false
			print("debounce 2")

		end
	end
end)

Can anybody give me a solution to this?

Any solutions to this?‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎

You should store your ammo in an IntValue, instead of making it a variable.

If its stored as a variable, how did you know the number of bullets in the server is zero without printing anything?

Stored it in an int value, and the problem still persists.

I knew how much ammo there was through the output and gui, both with conflicting amounts

Any helpers for this matter???

When you change the UI try tostring(ammo)…“/16”

while true do
					ammo = 0
					task.wait(2)
					break
				end

This might’ve fixed it?
Still leaving it unsolved in case I encounter this again