The counter works the first time I equip a weapon but every time I switch back to it, the print that shows after Parent.Equipped prints once for every time I have switched and re-equipped. Is there an alternative method that doesn't add an extra print every time I unequip and re-equip?
local MaxAmmo = 15
local Reloading = false
local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local TextLabel = playerGui:WaitForChild("AmmoDisplay"):FindFirstChild("AmmoText")
local Ammo = MaxAmmo
script.Parent.Equipped:Connect(function(Mouse)
print(Ammo)
local function Reload()
Reloading = true
wait(1)
Ammo = MaxAmmo
Reloading = false
end
script.Parent.Activated:Connect(function()
print("fired "..Ammo)
if Ammo > 0 and not Reloading then
Ammo -= 1
print(Ammo)
script.Parent.GunShot:Play()
--recoils--
if Mouse.Target.Parent:FindFirstChild("Humanoid") then
script.Parent.DealDamage:FireServer(Mouse.Target.Parent, 20)
end
elseif Reloading == false then
Reload()
script.Parent.GunShot:Stop()
end
while wait() do
TextLabel.Text = Ammo.."/"..MaxAmmo
end
end)
local Input = game:GetService("UserInputService")
Input.InputBegan:Connect(function(Key)
if Key.KeyCode == Enum.KeyCode.R and Reloading == false and Ammo ~= MaxAmmo then
Reload()
end
end)
end)

3 comments
Try putting the Activate function outside the Equipped function
Also, try putting the InputBegan thing outside too, or else, it will connect everytime you equip it.
I had taken a tutorial and made it my own by slowly adding changes as I see fit. Both of your ideas worked, all I had to do was break up the functions a little more. thanks guys!