Making a character move when a gui is clicked

local MainGui = script.Parent
local TextButton = MainGui.TextButton
local humanoid = workspace.Humanoid

TextButton.MouseButton1Down:Connect(function ()
	humanoid:Move(Vector3.new(0, 0, -1), true)
end)

I literally have no slightest idea how to make this work, also does someone know if there is something like MouseButton1Hold or anything, because I want to make it when player holds down M1 on that gui player moves forward

shouldnt humanoid refer to the humanoid in the character rather than some random humanoid in the workspace?

you probably want to use moveto

Anyways, I tested it and it seems you need to call :Move() from the server. So you will need a RemoteEvent in ReplicatedStorage, then put a script in ServerScriptService to tell it what to do.

To make the character only move forward while the button is pressed, you need to make use of the MouseButton1Down event to tell when it starts being pressed, and the MouseButton1Up event to tell when it has been released.

local ReplicatedStorage = game:GetService('ReplicatedStorage')
local remoteEvent = ReplicatedStorage:WaitForChild('RemoteEvent')

remoteEvent.OnServerEvent:Connect(function(player, buttonState)
    if buttonState = 'Pressed' then
        player.Character.Humanoid:Move(Vector3.new(0,0,-1), true)
    elseif buttonState == 'Released' then
        player.Character.Humanoid:Move(Vector3.new(0,0,0), true)
    end
end)

When you fire an remote event from a local script it automatically sends the info of which player activated it, so you can find the humanoid of the character using that. Then you will need to pass an extra variable i called ‘buttonState’ to tell if the button has been pressed or released

Then inside your original local script for the button you would have code which fires the event:

local ReplicatedStorage = game:GetService('ReplicatedStorage')
local remoteEvent = ReplicatedStorage:WaitForChild('RemoteEvent')

local MainGui = script.Parent
local TextButton = MainGui.TextButton

TextButton.MouseButton1Down:Connect(function ()
	remoteEvent:FireServer('Pressed')
end)

TextButton.MouseButton1Up:Connect(function ()
	remoteEvent:FireServer('Released')
end)

and for the other thing,
connect a loop when mousebutton1down that makes the player move forward

and disconnect it when mousebutton1up