Mouse.Button1Up lagging / failing to fire

I’m working on a gun system for my new game, I have everything else set-up and working though when I hold to shoot, then let go it sometimes does not stop firing- it seems to be pretty random whether is stops or keeps firing. I’ve tried using UserInputService but it responds the same way. This is the code:

	Mouse.Button1Down:Connect(function()
		if FireMode == "Semi" then
			if Ammo > 0 and Equipped and not Firing and not Reloading and not check then
				check = true
				spawn(Shoot)
				wait(FireRate)
				check = false
			end
		elseif FireMode == "Auto" then
			MouseDown = true
			while Ammo > 0 and Equipped --[[and not Firing]] and not Reloading and MouseDown and not check do
				check = true
				spawn(Shoot)
				wait(FireRate)
				check = false
			end
		end
	end)
	Mouse.Button1Up:Connect(function()
		if Equipped and Firing and FireMode == "Auto" then
			MouseDown = false
			FlashEffect.Enabled = false
			SmokeEffect.Enabled = false
			wait(FireRate-0.05)
			Firing = false
			RecoilAnim:Stop()
			RunService.RenderStepped:Wait()
		end
	end)

There are no errors. Thanks.

2 Likes

Use the User Input Service (UIS), it’s better and more supported I believe.

You can read up on the UIS by clicking the link right here, and if you have any questions please make sure to reply with them so I can help you out. :smile:

4 Likes

I’ll use UIS then, though I figured out what was causing the repsons issues. It wasn’t anything to do with any of the mouse functions, I had a varible “Firing” that was changing from true/false vary fast to it didn’t always catch it on true. Anyways, thanks for the advice.

1 Like