Help using :Move() with gui button

I have a Text gui when pressed it’s suppose to move the player, here’s the script(LocalScript in TextButton):

local function onTouchTap()
	local RL = game.ReplicatedStorage:WaitForChild("Players"):WaitForChild("MobileLeft")
	game.Players.LocalPlayer.Character:WaitForChild("Humanoid"):Move(Vector3.new(0, 0, -1), true)
end
local function Released()
	game.Players.LocalPlayer.Character:WaitForChild("Humanoid"):Move(Vector3.new(0, 0, -1), false)
end
script.Parent.MouseButton1Down:Connect(onTouchTap)
script.Parent.MouseButton1Up:Connect(Released)

Untitled design
(Sorry I’m new with scripting)

2 Likes

You must use RemoteEvents for this. From my understanding, I don’t think you can move players from the Client since other players are unable to view it. Simply make a RemoteEvent and fire it whenever a button is pressed, then move the player from the Server.

1 Like

It works but for some reason if I hold the gui down the player only moves less than a second:
Untitled design(1)
ServerScript in serverScriptService:

local ML = game.ReplicatedStorage.Players.MLeft
ML.OnServerEvent:Connect(function(Player)
Player.Character:WaitForChild("Humanoid"):Move(Vector3.new(0, 0, -1), true)
end)
local MR = game.ReplicatedStorage.Players.MLeft.RemoteEvent
MR.OnServerEvent:Connect(function(Player)
print("Released")
Player.Character:WaitForChild("Humanoid"):Move(Vector3.new(0, 0, -1), false)
end)
1 Like

You are going to have to hook the click event more than once, or bind to UserInputService and control the event more rigorously, i.e. when the click begins, as it continues, and when it ends, and continually fire RemoteEvents to fire the movement to happen (probably over some granulated time-scale).

1 Like

If it’s a normal player and not anchored by the server, you can move from the client. That’s exactly how normal roblox movement works. It’s client authoritative.

1 Like

Sorry I forgot to mention, I’m making it for mobile users

1 Like

Aight never used this function before so had to look it up. First of all the second argument you pass to Move doesn’t mean what you think it does. It’s a boolean called “relativeToCamera”, so you use it to enable or disable the movement direction being applied according to the camera. Therefore when you call it again in released with false, it’ll just send your guy moving in a different direction.

The second thing you need to do is go under StarterPlayer and set the default movement mode to Scriptable, because otherwise

When this function is called, the Humanoid will move until the function is called again. However, if the default control scripts are being used this function will be overwritten when called on Player Characters. This can be avoided by either not using the default control scripts, or calling this function every frame using RunService:BindToRenderStep() (see example).

This is all clearly written in the documentation so give that a look next time.

And then lastly, you can fix your released function by setting the moveDirection vector to 0, 0, 0.

2 Likes

Thank you all for helping me :+1:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.