You can write your topic however you want, but you need to answer these questions:
-
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. -
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. -
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