Player can spam reload to keep shooting without pause

I’ve got reloading along with reload cancelling that I made a while ago, and I recently found a glitch where you can spam the semi(and likely full auto) weapons while spamming r and basically keep shooting without having to really reload, it looks like this

https://streamable.com/ding49

V The code for reloading V

function reload()
    if canReload == true and humanoid.Health > 0  then
        canAim = false
        Reloading = true
        canShoot = false
        debounce = true
        reloadTrack:Play()
        tool.Reload:Play()
        wait(ReloadingTime)
        if Reloading == true then
            Reloading = false
            debounce = false
            canSlide = true
            canShoot = true
                if Sprinting.Value == false then
                    canAim = true
                end
            end
        end
    end
end

V The code for cancelling V
here is cancle coad

function cancelReload()
    if Ammo ~= 0  and humanoid.Health > 0 then
        Reloading = false
        canShoot = true
        tool.Reload:Stop()
        reloadTrack:Stop()
        canSlide = true
        canShoot2 = true
        canAim = true
        canReload = true
        canReload2 = true
        delay(0.2, noDebouncer)
    end
end

I’ve got debounce on firing and reloading, but they get overridden when you cancel reload, what’s going on here?

1 Like

You can possibly add a delay or wait until you set “canShoot” to true, I believe since you are setting it to true immediately, it’s allowing it to spam it. I’m not necessarily sure if that’ll work, but it’s worth a try ay :grinning_face_with_smiling_eyes:

I’ve tried that solution earlier with a “currentlyfiring” variable that I had a delay of 0.3 before it was set to false, and all the areas handling reload having a condition that it should be false. All this did was add a kind of weird delay to reloading after shooting, and it didn’t really do anything to fix the original issue

That shouldn’t have added a delay to reloading, it’s only meant to affect cancel reloading since that’s where the issue has arose from… weird…

What’s happening is you’re constantly changing Reloading, while reload() is still running

This means that every time you change Reloading to true outside of reload(), it’ll still replenish your ammo as long as Reloading == true when the if statement runs.

What I would do is make a new bool variable inside reload(), named “cancelled” for example, and change it to false every time the tool is activated (or whatever your fire keybind is), then check if the reload was cancelled at the if statement.

Barebones example:

I used this, and used userinputservice instead of an event, but the problem still remains
https://streamable.com/kdgsjy

I usually set reloading equal to tick() then I set a local variable inside reloading equal to reloading, then I check if reloading = localvar after the wait. This means to cancel a reload you just need to change the value of reload and it won’t be able enter the if statement to actually finish the reload and update the ammo. I usually change the value of reload to false to cancel so that I can still determine if they are currently reloading so it doesn’t reset if I press the button twice.

Something like this.

local reloading = false
local canShoot = true

function cancelReload()
  reloading = false
  canShoot = true
end


local function reload()
  if reloading then return end —on mobile and don’t want to tab more than necessary
  reloading = tick()
  canShoot= false
  local reloadCheck = reloading
  wait(5)
  if reloading == reloadCheck then
    —reload wasn’t canceled. Change ammo. 
    cancelReload() —resets the variables. Doesn’t actually cancel after it’s made it into this if statement
  end
end

Are you sure you’re using UserInputService correctly? E.g. If you added print(), does it print something out upon firing while reloading?

well it’s just under what checks if mousebutton1 is down, which allows for shooting, so yes I am

If you don’t mind, can you post a snippet of your reload() function?

sure,

cancelled should be defined within mainLoad(), as well as the tool.Activated/UserInputService connection, otherwise you’re having the exact same issue as before.

I’ll try this right now thanks

shouldn’t this be a different variable?

It’s being set to tick to give it a unique ID essentially. But if you mean if it’s spelt correctly to match up with how you did it, I forgot to capitalize it.

oh okay, never mind sorry
3030

worked perfectly once I understood what it’s doing, I didn’t really read much of your description, thanks though,

1 Like