Debounce doesn't actually debounce?

I’m making a reload script, and everything works just fine besides the fact you can mass spam R to get some crazy results.

To counter this i’m using debounce but for some reason debounce doesn’t do anything, and I don’t know why.

Incase anyone’s confused:

function reload(input, gameProcessed)
	if db == false then
		db = true
	if gameProcessed then return end
	
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.R then
			if Ammo.Value == 18 then return end
			if Ammo.Value < 18 then
				print("reloading")
				local animator = Humanoid:FindFirstChildOfClass("Animator")
				
				if animator then
					local reload = animator:LoadAnimation(ReloadAnim)
					reload:Play()
					
					
					reload.KeyframeReached:Connect(function(KeyframeName)
						if string.find(KeyframeName, "Pull") then
							PullSound:Play()
							Ammo.Value -= 18
							if Ammo.Value < 0 then
								Ammo.Value = 0
							end
							AmmoCounter.Text = "AMMO:" .. Ammo.Value .. "/18"
							print("Pulling out")
						end
						if string.find(KeyframeName, "In") then
							InsertSound:Play()
							Ammo.Value += 18
							AmmoCounter.Text = "AMMO:" .. Ammo.Value .. "/18"
							print("Putting in")
						end
					end)
				
				end
			end
		end
		end
	end
	task.wait(0.3) -- changing this to higher or lower doesn't change anything, you can still mass spam R
	db = false
end

You might have forgotten an end.

Nah the end is at the bottom, you can see two end stacked on top of eachother

1 Like

the ends are correct, but the placement of that debounce is incorrect :sob:

fixed, but thanks for pointing that out

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.