Hey im new to the moveto function. How do i move a localplayer to a part in the workspace? game.players.localplayer:moveto doesn't work. Can somebody help me out?
MoveTo() is not a function of the Player class; it is a function of humanoids. What you want to do is something like this.
1 | local Player = game:GetService( "Players" ).LocalPlayer |
2 | local Character = Player.Character or Player.CharacterAdded:wait() |
3 | local Humanoid = Character:WaitForChild( "Humanoid" ) |
4 | local TargetPosition = Vector 3. new(x,y,z) --Replace this with the position you want the player to move to. |
5 | local TargetPart = nil --If you want the player to walk toward a certain part, change this. |
6 |
7 | Humanoid:MoveTo(TargetPosition, TargetPart) |
This is not teleporting, the player will start walking in the direction of the Vector3. If you want to teleport, you would do something like this instead
1 | local Player = game:GetService( "Players" ).LocalPlayer |
2 | local Character = Player.Character or Player.CharacterAdded:wait() |
3 | local RootPart = Character:WaitForChild( "HumanoidRootPart" ) |
4 | local TargetPosition = Vector 3. new(x,y,z) --Replace this with the position you want the player to move to. |
5 |
6 | RootPart.CFrame = CFrame.new(TargetPosition) |
this is my teleport script on chat command. maybe u can learn from it.
001 | if message:sub( 1 , Teleport:len()):lower() = = Teleport:lower() then |
002 |
003 | local value = message:sub(Teleport:len() + 1 ) |
004 | local Rank = player.Ranking.Rank |
005 |
006 | if Rank.Value > 2 then |
007 |
008 | if value = = "mountain" or value = = "berg" then |
009 |
010 | local Player = game.Players:GetPlayerByUserId(player.UserId) |
011 | local target = CFrame.new( 446.388031 , 7 , - 607.283936 ) --...and this |
012 | local helper = Player.Character:FindFirstChild( "Helper" ) |
013 | local ZombieGameGui = Player.PlayerGui:FindFirstChild( "ZombieGameGui" ) |
014 | local path = helper.AI.Pathfinding |
015 |
happy scripting :D