Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

When the player presses a text button player walks to part?

Hello, I want the player to walk to a part when they press the text button, Heres my script:

local player = game.Players.LocalPlayer
local humanoid = player.Character.Humanoid
local part = game.Workspace.CameraPart
local plr = game.Players.LocalPlayer
local chr = plr.Character
script.Parent.MouseButton1Click:Connect(function()
if player.Character then 
	 player.Character.Humanoid:MoveTo(part.Position)
end

I've tried other scripts but I deleted them and don't remember them, can someone help me, please?

5 comments

0

What's wrong exactly? Any errors?

0

The player won't move.

0

too early, add an end) and wait for MoveToFinished.

0

I do have an end), in the developer console it says "Player:Move called, but player currently has no humanoid"

0

Wait for the humanoid to exist, then, using WaitForChild().

1 answer

✓ Accepted answer

Hello, I'm xWhiteHat. I'll be attempting to fix your issue with this script.

The reason it was printing the error about the end is because you forgot to add one, you only have one end and two functions that require an end after them. You forgot to add an end) for the MouseButton1Click, you only added one for the if statement. Also I recommend adding a WaitForChild() to wait for the Humanoid to load here. I've revamped your script and here is what I got.

local player = game.Players.LocalPlayer
local char = workspace:WaitForChild(player.Name)
local humanoid = workspace:WaitForChild(player.Name):WaitForChild("Humanoid")
local part = game.Workspace:WaitForChild("CameraPart")

script.Parent.MouseButton1Click:Connect(function()
	if char then 
	     humanoid:MoveTo(part.Position)
	end
end)

If you come across any issues feel free to reply and let me know!

~ xWhiteHat

2 comments

0

Thank you so much, it worked!

1

@isaacjh100 No problem, I'm glad it worked. Enjoy creating your game! :)

This discussion is preserved as it was. New answers, comments, and votes are closed.