I know this is a simple thing, but my brain is having a slight meltdown. Anyways, I’m working on a weapon, and I’m trying to get it to reload with ammo. When the ammo get’s to zero, it reloads back to max ammo. The problem is I want to be able to show that the ammo is ‘0’ for a brief duration before reloading. Currently, when the ammo reaches 0, it reloads back to max ammo, and you can’t tell it’s at 0.
What happens is: Ammo gets to zero, then goes to 5. What I want is ammo gets to 0, pause for a brief duration, maybe reloading gui & sound may play, and then goes to max ammo.
Any help would be much appreciated.
ReloadGui.Text = "Ammo: ".. MaxAmmo
local debounce = true
function Reload()
Ammo.Value = Ammo.Value - 1
if Ammo.Value == 0 then
print("reloading")
Ammo.Value = MaxAmmo
end
end
Tool.Activated:Connect(function()
if debounce then
debounce = false
Reload()
ReloadGui.Text = "Ammo: ".. Ammo.Value
print(Ammo.Value)
wait(5)
debounce = true
end
end)
Move the Reload() function after you set the text, and you want to decrement the Ammo before you change the text.
Here’s how it would look:
local debounce = true
function Reload()
if Ammo.Value == 0 then
-- Add wait here with the music playing--
Ammo.Value = MaxAmmo
-- Set The Text back to Max Ammo --
end
end
Tool.Activated:Connect(function()
if debounce then
debounce = false
Ammo.Value = Ammo.Value - 1
ReloadGui.Text = "Ammo: ".. Ammo.Value
Reload()
print(Ammo.Value)
wait(5)
debounce = true
end
end)
Thanks, this works. God Bless. I have one last question. In most weapons, is the reloading usually automatic or do you have to click to reload, because then I might need to consider it reloading without clicking again. What happens now is that it pauses briefly at 0, but I need to click again to reload, which is what I expected, but I’m slightly considering it reloading once it gets to 0, without the need to click again.
Most games I’ve played have the weapon reloading as soon as it hits 0. With that being said, you can just use GetPropertyChangedSignal to see if the Ammo’s value has reached 0, and if it has, invoke that reload function you’ve created.