I am making a zombie survival game and am making buttons for mobile compatibility but whenever I test the game and press the button there is a 5 to 7 second delay before the gun reloads but when I press R on my keyboard there is no delay so I’m not sure what the cause of it is.
This is the reload function
userInput.InputBegan:Connect(function(input, gameProcessed)
if not gameProcessed then
if input.UserInputType == Enum.UserInputType.Keyboard or player.PlayerGui.CameraGui.GameInfo.ReloadButton.MouseButton1Click then
local keycode = input.KeyCode
if keycode == Enum.KeyCode.R then
if gun.Ammo.Value < clipSize and gun.MaxAmmo.Value > 0 then
shooting = false
reload:Play()
reloadAnimation:Play()
reload.Ended:Wait()
if gun.MaxAmmo.Value - (clipSize - gun.Ammo.Value) >= 0 then
gun.MaxAmmo.Value = gun.MaxAmmo.Value - (clipSize - gun.Ammo.Value)
gun.Ammo.Value = clipSize
else
gun.Ammo.Value = gun.Ammo.Value + gun.MaxAmmo.Value
gun.MaxAmmo.Value = 0
player.PlayerGui.CameraGui.GameInfo.AmountAmmo.Text = ''.. tostring(ammo.Value)..'/'.. tostring(gun.MaxAmmo.Value)
end
end
end
end
end
end)