How to make player move with arrow buttons (For Mobile Users)

  1. What do you want to achieve? Make a control system that make player move if he click on arrow button so I want to make 2 buttons (arrows) one to make player move left and one to make player move right
  2. What is the issue? idk how to make it do that.
  3. What solutions have you thought of so far? Searching on YouTube but I didn’t saw anything about it

btw I already make arrows but idk how to script them to make player move if he click on them

Picture

1 Like

You’ll need to use ContextActionService | Roblox Creator Documentation or UserInputService | Roblox Creator Documentation and for mobile specifically you’ll want to look into the Touch based events.

I already do it for Pc users but idk how to do it for mobile

Just like for PC you need to hook your move routines to the “key”. In the case of mobile, “keys” are GUI objects like imageButtons or textbuttons etc…They have events like “TouchTap”. Link the event you want to the move routine.

Idk how to edit the pc script because I did not make it I made a topic and one make it for me

please anyone help this is my Pc Control script if anyone can edit it and make it work on mobile too

Note : they are local scripts and they are in StarterPlayerScripts

D Script (Right Arrow)

local Players = game:GetService("Players")

local player = Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()

local humanoid = Character:WaitForChild("Humanoid")
local Moving = false
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

UserInputService.InputBegan:Connect(function(keyCode, Chatted)

	if Chatted then
		return
	end

	local HRP = Character:FindFirstChild("HumanoidRootPart")

	if HRP ~= nil and keyCode.KeyCode == Enum.KeyCode.D then
		Moving = true

		while Moving do
			Character.Humanoid:Move(Vector3.new(0,0,1))
			RunService.RenderStepped:Wait()
		end

	end
end)

UserInputService.InputEnded:Connect(function(keyCode)
	local HRP = Character:FindFirstChild("HumanoidRootPart")

	if HRP ~= nil and keyCode.KeyCode == Enum.KeyCode.D then
		Moving = false
		Character:MoveTo(HRP.Position)
	end

end)

A script (Left Arrow)

local Players = game:GetService("Players")

local player = Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()

local humanoid = Character:WaitForChild("Humanoid")
local Moving = false
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

UserInputService.InputBegan:Connect(function(keyCode, Chatted)

	if Chatted then
		return
	end

	local HRP = Character:FindFirstChild("HumanoidRootPart")

	if HRP ~= nil and keyCode.KeyCode == Enum.KeyCode.A then
		Moving = true

		while Moving do
			Character.Humanoid:Move(Vector3.new(0,0,-1))
			RunService.RenderStepped:Wait()
		end

	end
end)

UserInputService.InputEnded:Connect(function(keyCode)
	local HRP = Character:FindFirstChild("HumanoidRootPart")

	if HRP ~= nil and keyCode.KeyCode == Enum.KeyCode.A then
		Moving = false
		Character:MoveTo(HRP.Position)
	end

end)