ContextActionService not picking up inputs

I’ve used CAT to bind a bunch of keys to functions, but now the game doesn’t pick up any other inputs like equipping tools and moving the camera around. Not sure why this is happening?

--//Inputs
ContextActionService:BindAction("EquipMain", Controls.Sort, true, Enum.KeyCode.One)
ContextActionService:BindAction("EquipSecondary", Controls.Sort, true, Enum.KeyCode.Two)
ContextActionService:BindAction("Reload", Controls.Sort, true, Enum.KeyCode.R)
ContextActionService:BindAction("Mouse1", Controls.Sort, true, Enum.UserInputType.MouseButton1)
ContextActionService:BindAction("Mouse2", Controls.Sort, true, Enum.UserInputType.MouseButton2)

local module = {}

local M1 = false
local M2 = false

local function IsActive(Input,State)
	local Player = game:GetService("Players").LocalPlayer
	local Mouse = Player:GetMouse()
	local Character = Player.Character or Player.CharacterAdded:Wait()
	for i,v in pairs(Character:GetChildren()) do
		if v:IsA("Tool") then
			if State == Enum.UserInputState.Begin then
				local Table = require(game:GetService("ReplicatedStorage").Modules.PlayerModules[Player.Name])
				print(Table)
				local Module = require(game:GetService("ReplicatedStorage").Modules.GunModules[v.Name])
				local Main = require(game:GetService("ReplicatedFirst"):WaitForChild("Loadout")[Table.Main.Name])
				local ProjectileModule = require(script:WaitForChild("Projectile"))
				shared.PrintPath.Print(Input)

				if Input == "Mouse1" then
					if Module.FireMode == 1 then
						while M1 do
							shared.PrintPath.Print("AutoFire")
							game:GetService("ReplicatedStorage").RemoteEvent:FireServer({T="ToolActivated",Input=Input,State=State,MousePos=Mouse.Hit.p,Tool=v})
							ProjectileModule.Basic(true,Mouse.Hit.p,v.FirePart.Position,Main.BulletSpeed)
							wait(Module.FireRate)
						end
					elseif Module.FireMode == 2 then
						for i = 1,Module.Burst do
							shared.PrintPath.Print("BurstFire")
							game:GetService("ReplicatedStorage").RemoteEvent:FireServer({T="ToolActivated",Input=Input,State=State,MousePos=Mouse.Hit.p,Tool=v})
							ProjectileModule.Basic(true,Mouse.Hit.p,v.FirePart.Position,Main.BulletSpeed)
							wait(Module.FireRate)
						end
					else
						shared.PrintPath.Print("SemiFire")
						game:GetService("ReplicatedStorage").RemoteEvent:FireServer({T="ToolActivated",Input=Input,State=State,MousePos=Mouse.Hit.p,Tool=v})
						ProjectileModule.Basic(true,Mouse.Hit.p,v.FirePart.Position,Main.BulletSpeed)
						wait(Module.FireRate)
					end
				end
				
				if Input == "Reload" then
					if not Main.Mag == Module.Mag then
						shared.PrintPath.Print("Reload")
						game:GetService("ReplicatedStorage").RemoteEvent:FireServer({T="ToolActivated",Input=Input,State=State,MousePos=Mouse.Hit.p,Tool=v})
					end
				end
				
			end
			break
		end
	end
end

function module.Sort(Input,State)
	if Input == "Mouse1" or Input == "Mouse2" then
		if Input == "Mouse1" then
			if State == Enum.UserInputState.Begin then
				M1 = true
				IsActive(Input,State)
			else
				M1 = false
				IsActive(Input,State)
			end
		elseif Input == "Mouse2" then
			if State == Enum.UserInputState.Begin then
				M2 = true
				IsActive(Input,State)
			else
				M2 = false
				IsActive(Input,State)
			end
		end
	end

	if Input == "Reload" then
		if State == Enum.UserInputState.Begin then
			IsActive(Input,State)
		else

		end
	end
end


return module

Could you show us your Controls.Sort function?

Yeah re-editted it’s there now

1 Like

Awesome. Looks like you put 2 arguments in your Sort function when there (should be?) 3.

The arguments passed by BindAction:

The function you passed to BindAction:
Screen Shot 2021-05-06 at 2.01.35 PM

All of this works fine

ContextActionService:BindAction("EquipMain", Controls.Sort, true, Enum.KeyCode.One)
ContextActionService:BindAction("EquipSecondary", Controls.Sort, true, Enum.KeyCode.Two)
ContextActionService:BindAction("Reload", Controls.Sort, true, Enum.KeyCode.R)
ContextActionService:BindAction("Mouse1", Controls.Sort, true, Enum.UserInputType.MouseButton1)
ContextActionService:BindAction("Mouse2", Controls.Sort, true, Enum.UserInputType.MouseButton2)

It’s other inputs like pressing 1 to equip a tool, default roblox inputs they don’t work. Adding the variable didn’t work.

Forgot to mention, you mixed up your Input and State arguments, State goes first, Input second. e.g:

 function module.Sort(ActionName,InputState,InputObject)

It literally doesn’t matter what I put in here:

function module.Sort(ActionName,InputState,InputObject)

It returns the same values in the same order the variable name doesn’t matter.

Yes, I am aware, I just got mixed up, sorry about that.

Could you explain what Table is, and what it does?

Its just game stats, the functions has no effect. I hooked it to an empty function and the same problem occurs.

function e()
	
end


--//Inputs
ContextActionService:BindAction("EquipMain", e, true, Enum.KeyCode.One)
ContextActionService:BindAction("EquipSecondary", e, true, Enum.KeyCode.Two)
ContextActionService:BindAction("Reload", e, true, Enum.KeyCode.R)
ContextActionService:BindAction("Mouse1", e, true, Enum.UserInputType.MouseButton1)
ContextActionService:BindAction("Mouse2", e, true, Enum.UserInputType.MouseButton2)

You need to put
return Enum.ContextActionResult.Pass
At the end of the each function that handles action.

I will refactor this later XD.

But seriously, it might have to be with the names of the actions.