How to make the player only go forward after pressing the gui button?

Hi,I took the code from DevHub.It only allows the player to go forward.

local RunService = game:GetService("RunService")
local Players = game:GetService("Players")

local localPlayer = Players.LocalPlayer

RunService:BindToRenderStep("move",
	-- run after the character
	Enum.RenderPriority.Character.Value + 1,
	function()
		if localPlayer.Character then
			local humanoid = localPlayer.Character:FindFirstChild("Humanoid")
			if humanoid then
				humanoid:Move(Vector3.new(0, 0, -1), true)
			end
		end
	end
)

How to make the player start moving after pressing the gui button and can move left and right horizontally?Im just new to scripting.
Bye!

This is what I can do, Hope it will be a guide for you.

local RunService = game:GetService("RunService")
local Players = game:GetService("Players")

local localPlayer = Players.LocalPlayer

script.Parent.TextButton.MouseButton1Click:Connect(function()
	RunService:BindToRenderStep("move", Enum.RenderPriority.Character.Value + 1, function()
		if localPlayer.Character then
			local humanoid = localPlayer.Character:FindFirstChild("Humanoid")
			if humanoid then
				humanoid:Move(Vector3.new(0, 0, -1), true)
			end
		end
	end)
	task.wait(1)
	RunService:UnbindFromRenderStep("move")
end)

ภาพถ่ายหน้าจอ 2565-01-01 เวลา 14.19.07

1 Like

Thanks for the help, but the player must move horizontally left and right and always move forward.