Shooting stops when pressing another key while holding the shoot button

Hello, I’ve made a shooting system that when holding Z it’ll fire shots from your character. The problem is that when you move/press any other key while holding Z it’ll stop shooting. How can I fix this?

https://i.gyazo.com/79a1bea7bae60e836907ad515e9ef5fd.gif

I’ve tried changing the script and switching it around and stuff but it doesn’t seem to work.

local UIS = game:GetService("UserInputService")
local Event = script:WaitForChild("ShootEvent")
local Shooting


UIS.InputBegan:Connect(function(Key,IsTyping)
	if IsTyping then return end
	Shooting = false
	
	if Key.KeyCode == Enum.KeyCode.Z and Shooting == false then
		Shooting = true
		while Shooting == true do
			if Shooting == false then break end
			Event:FireServer()
			task.wait(0.1)
		end
	end
end)


UIS.InputBegan:Connect(function(Key,IsTyping)
	if IsTyping then return end

	if Key.KeyCode == Enum.KeyCode.Z and Shooting == true then
		Shooting = false
	end
end)

So like you want your character to keep shooting even though the player presses other keys, and it will only stop when the player is no longer holding Z?

Yeah, pretty much. Sorry for late reply btw.

Only make shooting false when z is released, not when an input begins.

Oh, thanks. You also made me realize about the second InputBegan typo. Thanks again.

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