Help with custom move Gui

  1. What do you want to achieve?
    i want to make the player move if the player clicks a button.This is for a 2d game

  2. What is the issue?
    After i click nothing happens no error too
    image

  3. What solutions have you tried so far?
    checked the dev hub and devforum
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local localPlayer = game.Players.LocalPlayer
local RunService = game:GetService("RunService")

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

Thanks for reading!!

Change “humanoid:Move” to “humanoid:MoveTo”

1 Like

it still doesnt work now it says Unable To Cast Value To Object

1 Like

now it works but its moving forever

Put a print(“got here”) before you try to use the move function. Set back the function to Move instead of MoveTo

Here, I found a simialir script to yours, I got it from the wiki. I belive your script is wrote wrong. Try this:

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
)

i saw this but the problem is i want the player to move when the player clicks the button but this script makes the player move infinitely

Is the button a gui button? I need to know

yes its a gui button i showed an image of explorer

Try this script I made that should move the player while the button is being pressed down.

local button = script.Parent

local plr = game.Players.LocalPlayer

local character -- Contains the character.

if plr.Character then

character = plr.Character

end

plr.CharacterAdded:Connect(function(char)

-- Character for player has been loaded agian.

character = char

end)

button.MouseButton1Down:Connect(function()

if character then

character.Humanoid:Move(Vector3.new(0, 0, -1), true)

end

end)

it still didnt work :sob: :sob:

You should be using the Player’s Move function instead of using the Humanoid

Also why you are implementing 2 functions encased in each other? You can easily watch for when the Character moves by just the MouseButton1Click event

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Button = script.Parent

Button.MouseButton1Click:Connect(function()
    Player:Move(Vector3.new(0, 0, -1), false)
end)

Also, if you want world coordinates but not where the camera is pointing at, set the second parameter to false

hi here is my editted script

local button = script.Parent

local plr = game.Players.LocalPlayer

local character -- Contains the character.

if plr.Character then

	character = plr.Character

end

plr.CharacterAdded:Connect(function(char)

	-- Character for player has been loaded agian.

	character = char

end)

button.MouseButton1Click:Connect(function()

	if character then
		plr:Move(Vector3.new(0,0,-1), false)
		character.Humanoid:Move(Vector3.new(0, 0, -1), false)

	end

end)

it still doesnt work and no error in output

The character variable is only dependent on just getting the Player's Character, you aren’t checking for a CharacterAdded:Wait() event to yield until a character has been found

Use the code I tried, it should belong parented inside the buttont

i followed also didnt work
and note this is a textbutton

Are you sure you aren’t getting any errors? & you’re not moving the Character using your controls at all?

yes im not getting any errors and the character doesnt move

The only thing I can see is that your Player’s controls are overriding the Move function, can you try disabling the controls with this?

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Button = script.Parent
local PlayerControls = require(Player.PlayerScripts:WaitForChild("PlayerModule"))

local Controls = PlayerControls:GetControls()

Button.MouseButton1Click:Connect(function()
    Controls:Disable()
    Player:Move(Vector3.new(0, 0, -1), false)
end)

try to do this

    local button = script.Parent

    local player = game.Players.LocalPlayer

    button.MouseButton1Click:Connect(function()

    player.Character:MoveTo(Vector3.new(1, 0, 0))

    end)

That won’t work, as that’ll only Move the Character model instantly & not via world physics

Think of it as like changing the position of a part, you’re teleporting the part pretty much