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

MoveTo() teleport local player?

Asked by 5 years ago

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?

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

MoveTo() is not a function of the Player class; it is a function of humanoids. What you want to do is something like this.

1local Player = game:GetService("Players").LocalPlayer
2local Character = Player.Character or Player.CharacterAdded:wait()
3local Humanoid = Character:WaitForChild("Humanoid")
4local TargetPosition = Vector3.new(x,y,z) --Replace this with the position you want the player to move to.
5local TargetPart = nil --If you want the player to walk toward a certain part, change this.
6 
7Humanoid: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

1local Player = game:GetService("Players").LocalPlayer
2local Character = Player.Character or Player.CharacterAdded:wait()
3local RootPart = Character:WaitForChild("HumanoidRootPart")
4local TargetPosition = Vector3.new(x,y,z) --Replace this with the position you want the player to move to.
5 
6RootPart.CFrame = CFrame.new(TargetPosition)
0
MoveTo() is a model function and can move a model (such as the character) to teleport them. PhantomVisual 992 — 5y
0
Thank you! HoIyScript 51 — 5y
0
It is also a model function, but it is a function of Humanoid as well; if you're moving a Humanoid, you should use the Humanoid function. invalidinvoke 134 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

this is my teleport script on chat command. maybe u can learn from it.

001if 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 
View all 244 lines...

happy scripting :D

Answer this question