My MouseButton1 and 2 detections have just randomly stopped working

Usually, I find a forum with a similar issue or search on Google, but I can’t find a good solution to this. Because the solution that works also leads to another issue (I’ll address later on)

  1. What do you want to achieve? To have a working MB1 and MB2 keys for a fighting game

  2. What is the issue? My CombatClient script has randomly just stopped working. I have a good reason why I’m saying this, I swear, because the same script is present in another game, and it works flawlessly.

here is the script

local UIS = game:GetService("UserInputService")



local plr = game.Players.LocalPlayer
local character = plr.Character or plr.CharacterAdded:Wait()
local Humanoid = character:WaitForChild("Humanoid")
local M1 = Humanoid:LoadAnimation(script.Animations.M1)
local M2 = Humanoid:LoadAnimation(script.Animations.M2)
local M3 = Humanoid:LoadAnimation(script.Animations.M3)
local M4 = Humanoid:LoadAnimation(script.Animations.M4)


local combo = 1
local cooldown = false
UIS.InputEnded:Connect(function(I,E)
	if plr.Character:WaitForChild("Lobby").Value == true then return end
	if E then return end
	if I.UserInputType == Enum.UserInputType.MouseButton1 then
		if character:FindFirstChild("Stunned") then return end
		if cooldown == true then return end
		spawn(function()
			cooldown = true
			script.Swing:Play()
			task.wait(.5)
			cooldown = false
		end)
		if combo == 3 then
			game.ReplicatedStorage.MainEvent:FireServer("Last")
			M1:play()
			combo = combo + 1
			spawn(function()
				task.wait(.75)
				combo = 1
			end)
		elseif combo == 2 then
			game.ReplicatedStorage.MainEvent:FireServer("Regular")
			M2:play()
			combo = combo + 1
		elseif combo == 1 then
			game.ReplicatedStorage.MainEvent:FireServer("Regular")
			M1:play()
			combo = combo + 1
		end
	end
	if I.UserInputType == Enum.UserInputType.MouseButton2 and combo == 4 then
		if character:FindFirstChild("Stunned") then return end
		if cooldown == true then return end
		spawn(function()
			cooldown = true
			script.Swing:Play()
			task.wait(.5)
			cooldown = false
		end)
		game.ReplicatedStorage.MainEvent:FireServer("Bonus")
		M4:play()
		script.SwingKick:Play()
		spawn(function()
			task.wait(.1)
			combo = 1
		end)
	end
end)

-- Console edition Keybinds

local UIS = game:GetService("UserInputService")



local plr = game.Players.LocalPlayer
local character = plr.Character or plr.CharacterAdded:Wait()
local Humanoid = character:WaitForChild("Humanoid")
local M1 = Humanoid:LoadAnimation(script.Animations.M1)
local M2 = Humanoid:LoadAnimation(script.Animations.M2)
local M3 = Humanoid:LoadAnimation(script.Animations.M3)
local M4 = Humanoid:LoadAnimation(script.Animations.M4)



local combo = 1
local cooldown = false
UIS.InputEnded:Connect(function(I,E)
	if E then return end
	if I.KeyCode == Enum.KeyCode.ButtonB then
		if character:FindFirstChild("Stunned") then return end
		if cooldown == true then return end
		spawn(function()
			cooldown = true
			script.Swing:Play()
			task.wait(.5)
			cooldown = false
		end)
		if combo == 3 then
			game.ReplicatedStorage.MainEvent:FireServer("Last")
			M1:play()
			combo = combo + 1
			spawn(function()
				task.wait(.75)
				combo = 1
			end)
		elseif combo == 2 then
			game.ReplicatedStorage.MainEvent:FireServer("Regular")
			M2:play()
			combo = combo + 1
		elseif combo == 1 then
			game.ReplicatedStorage.MainEvent:FireServer("Regular")
			M1:play()
			combo = combo + 1
		end
	end
	if I.KeyCode == Enum.KeyCode.ButtonB and combo == 4 then
		if character:FindFirstChild("Stunned") then return end
		if cooldown == true then return end
		spawn(function()
			cooldown = true
			script.Swing:Play()
			task.wait(.5)
			cooldown = false
		end)
		game.ReplicatedStorage.MainEvent:FireServer("Bonus")
		M4:play()
		script.SwingKick:Play()
		spawn(function()
			task.wait(.1)
			combo = 1
		end)
	end
end)

My issue is, if I.UserInputType == Enum.UserInputType.MouseButton1 then is just being skipped over. causing none of my mouse keys to function, and the weirder issue is that the console method
if I.KeyCode == Enum.KeyCode.ButtonB then works without any issues

  1. What solutions have you tried so far? I tried converting UserInputType into KeyCode, which worked. But it also made every single key on the keyboard trigger that function

Sorry if I added too many details or words, never made a forum post before

maybe create a invisble textbutton that covers the screen and make a script ot detect if it’s clicked

InputBegan and InputEnded are deprecated

deprecated events still work, but its not recommended to use them as they could be removed in the future

Really? What are their replacements?

Input Action System

It favors physical Instances for input systems rather than UserInputService input events. It’s easier to learn and use as you don’t need to many disconnect/reconnect connections during specific events (e.g., enter vehicle, exit vehicle).

Of course since this is fairly new there are still some things UserInputService does better.

I think im gonna go with this option because im reading through it, and it looks a lot better than the original method for inputs

Okay so found a solution. The problem was an issue with another script conflicting with this one. Purely user error and that’s my bad… But the good news is that I learned how to use Input Action Service, which is making my game like 2X better, hooray I guess

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