Currently I am making a gun engine system, I am also currently making a shotgun. But the problem is, when the player reloads, instead of adding one to the ammo, it multiplies randomly instead.
uis.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.R then
if canReload then
if originalProperties.Ammo < 6 then
canReload = false
InsertAnim:Play()
InsertAnim:GetMarkerReachedSignal("Insert"):Connect(function()
script.Parent.OnReload:FireServer(script.Parent.Insert)
originalProperties.Ammo = originalProperties.Ammo + 1
ammoText.Text = tostring(originalProperties.Ammo) .. " / 120"
wait(.4)
canReload = true
end)
end
end
end
end)
This is the script. When there’s no ammo left, or there’s at least some ammo, instead of reloading one bullet in, instead it multiplies into something greater than 6 (which is the maximum ammo). Can anyone help me? I do not know what’s happening here. I already added a debounce (which is canReload) so I don’t think that’s the case.
Try putting a print() in there - it could potentially be that it’s firing multiple times, but just to make sure, try this:
uis.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.R then
if canReload then
if originalProperties.Ammo < 6 then
canReload = false
InsertAnim:Play()
InsertAnim:GetMarkerReachedSignal("Insert"):Connect(function()
script.Parent.OnReload:FireServer(script.Parent.Insert)
originalProperties.Ammo = originalProperties.Ammo + 1
ammoText.Text = tostring(originalProperties.Ammo) .. " / 120"
wait(.4)
canReload = true
print("Fired!")
end)
end
end
end
end)
Let me know if it prints “Fired!” multiple times, or just once. I’ll try to think of other possibilities in the meanwhile.
It fires multiple times for some reason, even though i have already included a debounce.

Ah so that’s what’s happening.
So, going from off the top of my head, the problem could be with one/multiple of the following:
- The
GetMarkerReachedSignal - By the way, what’s “Insert”?
- The
.InputBegan
- The debounce not working - I don’t see where you declared the
canReload variable, but from what I see, it should be working…
It’s quite strange, but it could also be something obvious (as usual with my code haha).
Never mind, I was able to fix it by disconnecting the “GetMarkerReachedSignal” event. Sorry for wasting everybody’s time! Haha.
1 Like
Ah nice, so it the problem did lie with that then.
Okay, it’s no problem, and you have a great day!