How do I make modify my maxAmmo to limited?

Hello. It has been a long time since I used the DevForum for help.

I’m following a tutorial on how to make an FPS game, but I have one major problem. The developer doing the tutorial hasn’t provided us with instructions on creating a limited maxAmmo. Thus, it has left me with one question: how do I make the limited amount of maxAmmo you have on your weapon?

Here is the code want to modify in the script, which follows the weapons from different module scripts.
Screenshot 2024-12-12 131715

Please do not hesitate to reply to me if you have any solutions.

Thanks,
Gamesensor300

Can you post the part of the module that is being called?

You could make use of either

math.clamp()

or

math.min()

As clamp is most applicable in this case IMO, you would do

framework.module.ammo = math.clamp(framework.module.ReserveAmmo, 0, MAXAMMO)

Replace MAXAMMO with whatever the maximum amount of ammo is.

Here is a sample of the module script of a gun based on the tutorial I watched.

You first need to make a variable with the total amount of bullets you currently have. After that, you add a if-logic next to the input.KeyCode == Enum.KeyCode.R statement, something like:

if input.KeyCode == Enum.KeyCode.R and framework.module.StoredAmmo > 0 then

After that, you can add, the following line AFTER the part where you do: framework.module.Ammo = ... that is, before the end.

framework.module.StoredAmmo -= framework.module.ReserveAmmo

I recommend sending in your script so we can help you in a better way.

Some side notes are that you should replace wait with task.wait which is more modern and accurate.

So, the whole script or just a section? Also, the ReserveAmmo is the StoredAmmo, though, or should I make another one?

Then replace StoredAmmo with reserved ammo? Make sure to add a variable called magazine capacity though. Ensure that it is used where you set the current ammo to reserved ammo.

Everything is all good now. I have looked at your suggestion and it now works. Thanks!

No problem! Glad to help.

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