Mobile controls for my game stop working when a computer user uses the computer controls

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I’m trying to make my game’s controls (originally made for computer) touchscreen compatible.
  2. What is the issue? Include screenshots / videos if possible!
    When testing I noticed that when a PC user uses the keyboard controls, the touchscreen controls stop working.
    Even weirder, there is one control where you click anywhere on the screen (on any device), which has the opposite effect (when a mobile user does it, it stops working for computers)
    The mobile controls are on a GUI with textbuttons. When they are clicked, a BindableEvent is fired which connects to the main script for that specific keybind.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I looked for solutions on the developer hub, couldn’t find anything, and couldn’t think of a possible solution myself

Here’s an example code for one of my controls (other controls work just about the same)

local swipeCooldown = false

game:GetService("UserInputService").InputBegan:Connect(function(inputObject, gameProcessedEvent)
	if ((inputObject.KeyCode == Enum.KeyCode.Q) or (inputObject.KeyCode == Enum.KeyCode.ButtonB)) and (not swipeCooldown) then
		if gameProcessedEvent then return end
		if not (game.Players.LocalPlayer.Name == game.Workspace.MonsterName.Value) then return end
		if swipeCooldown then return end
		if game.Players.LocalPlayer.Character:FindFirstChild("Puddle") then return end
		swipeCooldown = true
		local attackanim = Instance.new("Animation")
		attackanim.AnimationId = "rbxassetid://12013407121"
		local animtrack = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(attackanim)
		animtrack.Priority = Enum.AnimationPriority.Action
		animtrack:Play()
		game.Workspace.SwipeAttack:FireServer()
		animtrack.Stopped:Wait()
		task.wait(0.3)
		swipeCooldown = false
	end
end)

game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("Abilities"):WaitForChild("AttackButton")


game.Players.LocalPlayer.PlayerGui.Abilities.AttackButton.Event:Connect(function()
	if not (game.Players.LocalPlayer.Name == game.Workspace.MonsterName.Value) then return end
	if swipeCooldown then return end
	if game.Players.LocalPlayer.Character:FindFirstChild("Puddle") then return end
	swipeCooldown = true
	local attackanim = Instance.new("Animation")
	attackanim.AnimationId = "rbxassetid://12013407121"
	local animtrack = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(attackanim)
	animtrack.Priority = Enum.AnimationPriority.Action
	animtrack:Play()
	game.Workspace.SwipeAttack:FireServer()
	animtrack.Stopped:Wait()
	task.wait(0.3)
	swipeCooldown = false
end)

If you need it, here’s the script for the thing that happens when you click

local shootCooldown = false

game.Players.LocalPlayer:GetMouse().Button1Down:Connect(function()
	if #game.Players.LocalPlayer.PlayerGui:GetGuiObjectsAtPosition(game.Players.LocalPlayer:GetMouse().X, game.Players.LocalPlayer:GetMouse().Y) > 0 then return end
	if not (game.Players.LocalPlayer.Name == game.Workspace.MonsterName.Value) then return end
	if shootCooldown then return end
	if game.Players.LocalPlayer.Character:FindFirstChild("Puddle") then return end
	shootCooldown = true
	local mouse = game.Players.LocalPlayer:GetMouse()
	game.Workspace.ArmShoot:FireServer(mouse.Hit.Position)
	task.wait(1)
	shootCooldown = false
end)

game:GetService("UserInputService").InputBegan:Connect(function(inputObject, gameProcessedEvent)
	if gameProcessedEvent then return end
	if not (inputObject.KeyCode == Enum.KeyCode.ButtonL2) then return end
	if not (game.Players.LocalPlayer.Name == game.Workspace.MonsterName.Value) then return end
	if shootCooldown then return end
	if game.Players.LocalPlayer.Character:FindFirstChild("Puddle") then return end
	shootCooldown = true
	local mouse = game.Players.LocalPlayer:GetMouse()
	game.Workspace.ArmShoot:FireServer(mouse.Hit.Position)
	task.wait(1)
	shootCooldown = false
end)

game.UserInputService.TouchTapInWorld:Connect(function(position, processedByUI)
	if processedByUI then return end
	if not (game.Players.LocalPlayer.Name == game.Workspace.MonsterName.Value) then return end
	if shootCooldown then return end
	print("Mobile arm shoot")
	if game.Players.LocalPlayer.Character:FindFirstChild("Puddle") then return end
	shootCooldown = true
	local mouse = game.Players.LocalPlayer:GetMouse()
	print(mouse.Hit.Position)
	game.Workspace.ArmShoot:FireServer(mouse.Hit.Position)
	task.wait(1)
	shootCooldown = false
end)

If you think the problem is with another script please tell me

You’re using two seperate methods for controling the monster. The first is with the keyboard and the second is with a custom GUI button. I’m not sure if your custom button is a custom GUI button or a normal button, but I’m just going to assume it’s a normal button.
I can see the problem right away. Your problem is that you’re using two different methods to control the monster. This means that you have to seperate the code into two seperate scripts. One script will control the monster using the keyboard and one script will control the monster using the GUI button.
To fix this, create two seperate scripts. One script will be called “MonsterControls” and the other will be called “MonsterButtonControls”. Put the “MonsterControls” script inside the “StarterGui” and the “MonsterButtonControls” script inside the “StarterPack”.
Inside the “MonsterControls” script, put this code:


game:GetService("UserInputService").InputBegan:Connect(function(inputObject, gameProcessedEvent)
 if ((inputObject.KeyCode == Enum.KeyCode.Q) or (inputObject.KeyCode == Enum.KeyCode.ButtonB)) and (not swipeCooldown) then
  if gameProcessedEvent then return end
  if not (game.Players.LocalPlayer.Name == game.Workspace.MonsterName.Value) then return end
  if swipeCooldown then return end
  if game.Players.LocalPlayer.Character:FindFirstChild("Puddle") then return end
  swipeCooldown = true
  local attackanim = Instance.new("Animation")
  attackanim.AnimationId = "rbxassetid://12013407121"
  local animtrack = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(attackanim)
  animtrack.Priority = Enum.AnimationPriority.Action
  animtrack:Play()
  game.Workspace.SwipeAttack:FireServer()
  animtrack.Stopped:Wait()
  task.wait(0.3)
  swipeCooldown = false
 end
end)

The “MonsterButtonControls” script will be the one you use to control the monster. In that script, put this code:


local swipeCooldown = false

game.Players.LocalPlayer.PlayerGui.Abilities.AttackButton.Event:Connect(function()
 if not (game.Players.LocalPlayer.Name == game.Workspace.MonsterName.Value) then return end
 if swipeCooldown then return end
 if game.Players.LocalPlayer.Character:FindFirstChild("Puddle") then return end
 swipeCooldown = true
 local attackanim = Instance.new("Animation")
 attackanim.AnimationId = "rbxassetid://12013407121"
 local animtrack = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(attackanim)
 animtrack.Priority = Enum.AnimationPriority.Action
 animtrack:Play()
 game.Workspace.SwipeAttack:FireServer()
 animtrack.Stopped:Wait()
 task.wait(0.3)
 swipeCooldown = false
end)

Hope this helps!

I tried separating the scripts but it didn’t do anything for me. Not sure if it’s just the roblox studio device emulator (which I didn’t mention I was using) that has a problem