Hello everyone. Recently I made a debounce for my gun this debounce was made for a shooting cooldown because you could just spam click. I managed to make the debounce but then I had a problem. I also had a gui that shows how much ammo you have left until you have to reload. The gui was supposed to change the value down by 1 the problem is that whenever I shoot my gun the gui/ammo counter would reset back to 10.
Here is a example:
And this is my current main script:
Debounce = true
local maxAmmo = 10
local Ammo = maxAmmo
local reloading = false
local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild(“PlayerGui”)
local textLabel = playerGui:WaitForChild(“AmmoDisplay”):FindFirstChild(“AmmoText”)
script.Parent.Equipped:Connect(function(Mouse)
local function reload()
reloading = true
wait(1)
Ammo = maxAmmo
reloading = false
end
script.Parent.Activated:Connect(function()
if Ammo > 0 and not reloading then
Ammo = Ammo - 1
script.Parent.GunShot:Play()
if Debounce == true then
Debounce = false
if Mouse.Target.Parent:FindFirstChild("Humanoid") then
script.Parent.Fire:FireServer(Mouse.Target.Parent, 35)
wait(1)
Debounce = true
end
elseif reloading == false then
reload()
script.Parent.GunShot:Stop()
while wait() do
textLabel.Text = (Ammo).." / "..maxAmmo
end
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)
end)
Can anyone help?
Thanks!