Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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?

0
What's wrong exactly? Any errors? starmaq 1290 — 5y
0
The player won't move. isaacjh100 41 — 5y
0
<eof> too early, add an end) and wait for MoveToFinished. Fifkee 2017 — 5y
0
I do have an end), in the developer console it says "Player:Move called, but player currently has no humanoid" isaacjh100 41 — 5y
0
Wait for the humanoid to exist, then, using WaitForChild(). DeceptiveCaster 3761 — 5y

1 answer

Log in to vote
0
Answered by
NotedAPI 810 Moderation Voter
5 years ago

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

0
Thank you so much, it worked! isaacjh100 41 — 5y
1
@isaacjh100 No problem, I'm glad it worked. Enjoy creating your game! :) NotedAPI 810 — 5y
Ad

Answer this question