How do I change AmmoCount to MagCount UI?

I’m currently trying to modify a gun system called the Spearhead system and I’m testing and changing the value of ammocount to mag count but since i have 0 experiencing with scripting or programming im just stuck and don’t know what to do, I want to change the value from this (Pic 1) to something like this (Pic 2).

Example:
Pic 1:
image
Pic 2:
image

Here is the script responsible for ammo UI function:

local fireMode = ammoUI.FireMode
local chambered = ammoCounter.Chambered

local fireModeNames = {"SAFE", "[S]", "[F]", "[B]", "[M]"}

character.ChildAdded:Connect(function(newChild)
	if newChild:FindFirstChild("SPH_Weapon") and assets.WeaponModels:FindFirstChild(newChild.Name) and not dead then
		tool = newChild
		magAmmo = tool:WaitForChild("Ammo").MagAmmo
		ammoPool = tool.Ammo.ArcadeAmmoPool
		wepStats = require(tool.SPH_Weapon.WeaponStats)
		bulletType.Text = wepStats.ammoType
	end
end)

character.ChildRemoved:Connect(function(oldChild)
	if oldChild == tool then
		tool = nil
	end
end)

runService.Heartbeat:Connect(function()
	if tool and tool:FindFirstChild("Chambered") and magAmmo and not dead then
		ammoUI.Visible = true
		if not wepStats.operationType or type(wepStats.operationType) == "string" then wepStats.operationType = 3 end
		if wepStats.operationType == 1 and tool.Chambered.Value then
			ammoCounter.AmmoCount.Text = magAmmo.Value + 1
		else
			ammoCounter.AmmoCount.Text = magAmmo.Value
		end
		ammoPoolUI.Text = "/"
		if wepStats.infiniteAmmo then
			ammoPoolUI.Text = ammoPoolUI.Text.."INF"
		else
			ammoPoolUI.Text = ammoPoolUI.Text..ammoPool.Value
		end
		if tool.FireMode.Value == 0 then
			ammoCounter.AmmoCount.TextColor3 = Color3.new(0.5,0.5,0.5)
		elseif tool.Chambered.Value then
			ammoCounter.AmmoCount.TextColor3 = Color3.new(1, 1, 1)
		end
		fireMode.Text = fireModeNames[tool.FireMode.Value + 1]
	else
		ammoUI.Visible = false
	end
end)

character.Humanoid.Died:Connect(function()
	dead = true
end)

The code is specific to that GUI display in Pic 1. You will need to make a new GUI that looks like Pic 2 (or get one already done) and write new code for it. A big part of weapon kits is accounting. So you will need to add accounting for each thing you want to track. Sorry, I don’t have a better answer for you. Gun kits are complicated, especially if you’re modifying one that you didn’t write.

Since you’re new to programming, the best advise that I can give is watch YouTube videos on the basics of writing software and do it. There’s also lots of free online resources (tutorials, courses, etc…) that will help you as well. When writing software, you have to think like the computer. That requires math and logic. Another thing to consider is that computers are actually dumb machines. They will follow the steps that you give it, in order, precisely and explicitly, nothing more and nothing less. For example, if you tell a computer to go jump off a bridge, it won’t hesitate. It’s the software that gives the machines intelligence, but even then it’s limited.

The key is modifying these value objects within the runservice connection which constantly updates the gui

Currently its ammoPool as its the total ammo I believe you will have to do some prints to make sure. To convert the number into mags you can divide it by maximum mag capacity.

However you may end up with an non integer number so what happens next is up to you, you can round it down, remove the extra decimals and such.

I see. I’m trying to learn how to coding but my brain is too dumb for it. Oh about the UI, i’ve prepared one, its just i dont know what changes for it.

wait so i have to change the UI also? So far this is the UI be looks like.
image

Make it so you lose 1 ammo when reloading and change it so it fully reloads the gun instead

local Magsize=30
local Magazine=--the  amount of ammo in the gun
local MagCount=4

local function reload()
if Magsize<Magazine then return end --gun is already loaded
MagCount-=1 --remove a magazine from the players inventory
if Magazine>0 then --One in the chamber
Magazine=Magsize+1
else Magazine=Magsize
end
end

--help i don't know how to indent in devforum

This is just an example you’re gonna have to mess around with the system you already have but this is somewhat what it should resemble

1 Like

I see… Thank you for helping me!

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