Ammo system reloads too much ammo

I want to make it so that when you reload it only takes 25 of your max ammo.

Currently it usually works the first reload (not always) and then suddenly it will reload a 100 or more, or 50. I have no errors in the console. I have tried looking on the devforum but found nothing.

First Reload:
1sss

Then the second reload it did 25 again but then the third reload:
2sss
It took way more.
Reload Part:

game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.R then
		if toolEquipped == true then
			MouseHold2 = false
			waist.C0 = waistC0
			tool.ReloadEvent:FireServer()
			aimTrack:Stop()
			OTS_CAMERA_SYSTEM:Disable()
			toolEquipped = false
			reloadTrack:AdjustSpeed(tool.Configuration.ReloadTime.Value)
			reloadTrack:Play()
			wait(tool.Configuration.ReloadTime.Value)
			toolEquipped = true
		end
	end 
end)

Shoot part:

while true do
	if MouseHold then
		UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
		UserSettings():GetService("UserGameSettings").RotationType = Enum.RotationType.CameraRelative
		cam.CFrame = Camera.CFrame
		waist.C0 = waistC0 * CFrame.fromEulerAnglesYXZ(math.asin(Camera.CFrame.LookVector.Y)*1, 0, 0)
		if MouseHold2 then -- the left mouse button
			if player.PlayerGui.Ammo.Frame.Ammo.Text >= "1" then
				if player.PlayerGui.Ammo.Frame.MaxAmmo.Text >= "1" then
					tool.ShootEvent:FireServer(Mouse.Hit)
					shootTrack:Play()
					--if canShoot == true then
						--canShoot = false
						--local randomy = (math.random(0,strengthy*2)-strengthy)/1200
						--game.Workspace.CurrentCamera.CFrame = game.Workspace.CurrentCamera.CFrame*CFrame.Angles(strengthx/360/2,randomy/4,0)
						--wait(tool.Configuration.FireSpeed.Value)
						--canShoot = true
					--end
				end
			end
		end
	end
	wait()
end


Server SCript I forgot to include:

tool.ReloadEvent.OnServerEvent:Connect(function(plr)
		wait(tool.Configuration.ReloadTime.Value)
		plr.PlayerGui.Ammo.Frame.Ammo.Text = 25
		plr.PlayerGui.Ammo.Frame.MaxAmmo.Text = plr.PlayerGui.Ammo.Frame.MaxAmmo.Text - 25
	end)
1 Like

Try dont use >= "1" instead use >= 1.

Also can you do while true do to while wait() do

Hope it helps.

Does not work, it just gives the error Players.CreatarRoblox.Backpack.MPX.Local:142: attempt to compare number <= string since its a string

Use the tonumber() function to convert a string to a number.

For example tonumber(“123”) will return a number value of 123.

Thank you this fixed it. :> I used it in the server script to substract 25 from the max ammo and that was all it needed to make it work.