Anyone has an idea to make this part of the script auto-reload?

Hi scripters!

I am working on a gun system and since I aint the best scripter out there, I was wondering if any of you had a peice of code that I could add or change to make my guns auto-reload with no need to press the R button. Here is the part of the script where I think is the place to change it.

‘’'lua
–KeyDown functions
is.InputBegan:Connect(function(key,gpe)
if not gpe and equipped then

		if key.KeyCode == Enum.KeyCode.R then
			if reloading then 
				return 
			end
			if not sprint then
				reloading = true
				updateGUI()
				sound:FireServer(reload)
				
				reloadAnim:Play()
				wait(reloadTime.Value)
				reloading = false
				ammo.Value = ammo.MaxValue
				updateGUI()
			end

‘’’


if key.KeyCode == Enum.KeyCode.R then

			if reloading then 
				return 
			end
			if not sprint then
				reloading = true
				updateGUI()
				sound:FireServer(reload)
				
				reloadAnim:Play()
				wait(reloadTime.Value)
				reloading = false
				ammo.Value = ammo.MaxValue
if ammo.Value < 1 then 
reloading = true
				updateGUI()
				sound:FireServer(reload)
reloadAnim:Play()
				wait(reloadTime.Value)
				reloading = false
				ammo.Value = ammo.MaxValue
end

				updateGUI()

			end

I have changed it and sadly doesn’t self reload