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?
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