I'm trying to make a gun for my roblox game, and I want a GUI to give info to the player, like how much ammo is left in a clip, whether or not you're reloading etc. I am trying to get the variable "Ammo" 's value (12) into the text for the textbox, and have it decrease by 1 when it's fired. My code is:
local canFire = true
local Ammo = 12
local maxAmmo = 12
local ammoCounterText = game.StarterGui.ScreenGui.Frame.AmmoCounter.Text
script.Parent.Equipped:Connect(function(mouse)
mouse.Button1Down:Connect(function()
if canFire then
game.ReplicatedStorage.RayCastEvent:FireServer(script.Parent.ForBullets.Position, mouse.Hit.Position)
Ammo = Ammo - 1
ammoCounterText = Ammo
canFire = false
wait(0.5)
canFire = true
end
end
)
if Ammo < 1 then
canFire = false
wait(5)
Ammo = 12
canFire = true
end
end)

4 comments
Where did you learn how to script?
I added the things you requested into my LocalScript, however when I fire the gun, nothing changes.
@iivSnooxy I learned by watching YouTube videos and eventually I accumulated enough knowledge to help others out.
@Br_eden Did you put the last code snippet in my post into the event listener?