Mobile Support causing the game to randomly fire remotes on PC?

So I’ve recently added mobile support onto my game, but it’s causing me on the pc to randomly fire server at random times such as at the start of the game.

UserInputService.InputBegan:Connect(function(Input, IsTyping)
	if IsTyping then return end
	
	if Statuses.Casting.Value or Statuses.Chatting.Value then return end
	local Character = Player.Character
	if not Character or not Character.PrimaryPart then return end
	
	-- Summon Stand
	if Input.KeyCode == Enum.KeyCode.Q 
	or Input.KeyCode == Enum.KeyCode.E
	or Input.KeyCode == Enum.KeyCode.R
	or Input.KeyCode == Enum.KeyCode.T then
		requestAbility:FireServer(Input.KeyCode.Name)
	elseif Input.KeyCode == Enum.KeyCode.X
	or Input.KeyCode == Enum.KeyCode.C then
		requestPower:FireServer(Input.KeyCode.Name)
	elseif Input.KeyCode == Enum.KeyCode.F then
		requestBlock:FireServer()
		while UserInputService:IsKeyDown(Enum.KeyCode.F) do
			wait()
		end
		requestBlock:FireServer()
	elseif Input.KeyCode == Enum.KeyCode.P then
		interact()
	elseif Input.KeyCode == Enum.KeyCode.Space then
		if tick() - module.lastSpace <= 0.3 then
			if tick() - lastDash >= 2 then
				lastDash = tick()
				local LoadDash = Character.Humanoid:LoadAnimation(ReplicatedStorage.Animations.Player.Dash)
				LoadDash:Play()
				
				local velocity = GlobalFunctions.createInstance({
					instance = "BodyVelocity",
					properties = {
						Name = "DashVelocity",
						Velocity = Camera.CFrame.LookVector*70,
						MaxForce = Vector3.new(1,1,1)*1000000,
						Parent = Character.PrimaryPart				
					}
				})
				Debris:AddItem(velocity, 0.2)
				
				module.lastSpace = tick()
				requestDash:FireServer()
			end
		else
			module.lastSpace = tick()
		end
	elseif Input.UserInputType == Enum.UserInputType.MouseButton1 then
		requestPunch:FireServer()
	end
end)

--|| MOBILE ||--
local function requestSkillQ()
	requestAbility:FireServer("Q")
end

local function requestSkillE()
	requestAbility:FireServer("E")
end

local function requestSkillR()
	requestAbility:FireServer("R")
end

local function requestSkillT()
	requestAbility:FireServer("T")
end

local function punch()
	requestPunch:FireServer()
end

ContextActionService:BindAction("Interact", interact, true, Enum.KeyCode.P, Enum.KeyCode.ButtonR1)
ContextActionService:SetTitle("Interact", "Interact")
ContextActionService:SetPosition("Interact", UDim2.new(0.8, 0, -0.2, 0))

ContextActionService:BindAction("Punch", punch, true, Enum.UserInputType.MouseButton1, Enum.KeyCode.ButtonR1)
ContextActionService:SetTitle("Punch", "Punch")
ContextActionService:SetPosition("Punch", UDim2.new(0.1, 0, 0.3, 0))

ContextActionService:BindAction("QSkill", requestSkillQ, true, Enum.KeyCode.Q, Enum.KeyCode.ButtonR1)
ContextActionService:SetTitle("QSkill", "Q Skill")
ContextActionService:SetPosition("QSkill", UDim2.new(0.75, 0, 0.3, 0))

ContextActionService:BindAction("ESkill", requestSkillE, true, Enum.KeyCode.E, Enum.KeyCode.ButtonR1)
ContextActionService:SetTitle("ESkill", "E Skill")
ContextActionService:SetPosition("ESkill", UDim2.new(0.55,0,0.25,0))

ContextActionService:BindAction("RSkill", requestSkillR, true, Enum.KeyCode.R, Enum.KeyCode.ButtonR1)
ContextActionService:SetTitle("RSkill", "R Skill")
ContextActionService:SetPosition("RSkill", UDim2.new(0.35,0,0.3,0))

ContextActionService:BindAction("TSkill", requestSkillT, true, Enum.KeyCode.T, Enum.KeyCode.ButtonR1)
ContextActionService:SetTitle("TSkill", "T Skill")
ContextActionService:SetPosition("TSkill", UDim2.new(0.25,0,0.5,0))

I’ve set up the keys right under the userinputservice. Could someone tell me what I’m doing wrong?

1 Like

It’s not immediately clear to me what the problem might be. What data is the client sending to the server when the events randomly fire? Is it specific events and parameters or seemingly random?

1 Like

No data is sent other then the input keycode name which seems to be correct. It just seems like it’s connected to something else

This is happening because you don’t check the input state fired with context action service.

You should be doing something like:

local function requestSkillQ(name, inputState, input)
	if inputState == Enum.UseInputState.Begin then
		requestAbility:FireServer("Q")
	end
end

Otherwise whenever any other action binds over your actions you will fire the event to the server. You will also fire it for both the Begin and End state for each keypress.

See the description of the action binding stack here for more information:

3 Likes

So all I would have to do is add the 3 arguments in the function parameters and as well as check if the inputstate is begin? I’ve also noticed that sometimes other keybinds such as the escape b will run for the bag.

EDIT: Should I be checking if the player is on a mobile device before binding?

EDIT2: Since I’m repeating a lot of this code, I was wondering if I could make a function for it:

local function addMobileButton(BindName, BindTitle, Function, EnumCode, Pos)
ContextActionService:BindAction(BindName, Function, true, EnumCode, Enum.KeyCode.ButtonR1)
ContextActionService:SetTitle(BindName, BindTitle)
ContextActionService:SetPosition(BindName, Pos)
end

My biggest concern is passing a function as an argument into the function. I was also wondering in BindAction what the third argument true and the last argument Enum.KeyCode.ButtonR1 do.

Sorry I have a lot of questions, this is my first time using ContextActionService and adding mobile support.

Try to avoid using both User Input Service with Context Action Service.

The “IsTyping” Variable is actually a GameProcessingEvent which returns if the input was processed by the game engine or not. Since you’re passing the input in Context Action Service, which is considered an engine processing event, the User Input Service is just skipping over it due to:

So your first code isn’t even running.


As for you’re issue, try limiting the inputs by attaching the mobile request to this button. Of course, I’m not totally sure how that would look. You should probably experiment on your side, but that’s the path I would use.

The funny thing is it works like both UserInputService and ContextActionService. They both are overriding each other.

Why do you have them both? Wouldn’t it be best just to have ContextAction?

I don’t know how context action service works, would it be able to do both at the same time? Could you write me a sample code?

Your ContextAction code is in fact, already doing both. I also noticed, you could cut out the extra Enum.KeyCode.ButtonR1 from the BindAction call. I don’t even know what button that is or why it’s in there.

I took the code directly from the wiki so I’m not to sure what it does. So your telling me if I remove all the UserInputService code it will already be fine? Isn’t the contextaction binded to mobile buttons?

I would just comment the entire section with Ctrl + Shift + C before actually deleting the UserInput code. But yes, you’ve added a physical/gui button for players to click on for mobile.