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 4 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 4 years ago
Edited 4 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.

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local Humanoid = Character:WaitForChild("Humanoid")
local TargetPosition = Vector3.new(x,y,z) --Replace this with the position you want the player to move to.
local TargetPart = nil --If you want the player to walk toward a certain part, change this.

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

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local RootPart = Character:WaitForChild("HumanoidRootPart")
local TargetPosition = Vector3.new(x,y,z) --Replace this with the position you want the player to move to.

RootPart.CFrame = CFrame.new(TargetPosition)
0
MoveTo() is a model function and can move a model (such as the character) to teleport them. PhantomVisual 992 — 4y
0
Thank you! HoIyScript 51 — 4y
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 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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

if message:sub(1, Teleport:len()):lower() == Teleport:lower() then

        local value = message:sub(Teleport:len() + 1)
        local Rank = player.Ranking.Rank

        if Rank.Value > 2 then

            if value == "mountain" or value == "berg" then

                local Player = game.Players:GetPlayerByUserId(player.UserId)
                local target = CFrame.new(446.388031, 7, -607.283936) --...and this
                local helper = Player.Character:FindFirstChild("Helper")
                local ZombieGameGui = Player.PlayerGui:FindFirstChild("ZombieGameGui")
                local path = helper.AI.Pathfinding

                if ZombieGameGui then

                    ZombieGameGui:Destroy()

                end

                if helper then

                    local path = helper.AI.Pathfinding

                    if path.Disabled == false then

                        path.Disabled = true

                    end

                end

                local sparkles = Instance.new("Sparkles")
                    sparkles.Parent = player.Character:FindFirstChild("HumanoidRootPart")
                    sparkles.SparkleColor = Color3.new(225/255, 0/255, 0/255)
                wait(1)
                function fadeTo(a, b, c)
                    for transparency = a, b, c do
                        --go from a to b, counting by c

                        for _, part in pairs(player.Character:GetChildren()) do
                            --for each of the objects in the character,

                            if part:IsA("MeshPart") or part:IsA("BasePart") or part == "Head" then
                                --check if it's a part, and if so
                                if part.Name ~= "HumanoidRootPart"then
                                    part.Transparency = transparency
                                else
                                    part.Transparency = 1
                                end

                                --set its transparency
                            end

                            if part:IsA("Accessory") then
                                for _, part in pairs(part:GetChildren()) do
                                    if part:IsA("Part") then
                                        part.Transparency = transparency
                                    end
                                end
                            end
                        end
                    wait(0.1)
                    end
                end

                fadeTo(0, 1, 0.1) --fade out,
                player.Character.HumanoidRootPart.CFrame = target --teleport the player
                fadeTo(1, 0, -0.1) --fade back in
                player.Character.HumanoidRootPart.Transparency = 1
                    sparkles:Destroy()      


                if helper then

                    local mining = helper.Mining

                    if mining.Disabled == true then

                        path.Disabled = false
                    end
                end

            end

            if value == "sell" or value == "store" or value == "shop" then

                local Player = game.Players:GetPlayerByUserId(player.UserId)
                local target = CFrame.new(960.21167, 7, 685.763977) --...and this
                local helper = Player.Character:FindFirstChild("Helper")
                local ZombieGameGui = Player.PlayerGui:FindFirstChild("ZombieGameGui")
                local path = helper.AI.Pathfinding

                if ZombieGameGui then

                    ZombieGameGui:Destroy()

                end

                if helper then

                    local path = helper.AI.Pathfinding

                    if path.Disabled == false then

                        path.Disabled = true

                    end

                end

                local sparkles = Instance.new("Sparkles")
                    sparkles.Parent = player.Character:FindFirstChild("HumanoidRootPart")
                    sparkles.SparkleColor = Color3.new(225/255, 0/255, 0/255)
                wait(1)
                function fadeTo(a, b, c)
                    for transparency = a, b, c do
                     --go from a to b, counting by c

                        for _, part in pairs(player.Character:GetChildren()) do
                        --for each of the objects in the character,

                            if part:IsA("MeshPart") or part:IsA("BasePart") or part == "Head" then
                            --check if it's a part, and if so
                              if part.Name ~= "HumanoidRootPart"then
                                part.Transparency = transparency
                              else
                                part.Transparency = 1
                              end

                             --set its transparency
                            end

                            if part:IsA("Accessory") then
                                for _, part in pairs(part:GetChildren()) do
                                    if part:IsA("Part") then
                                        part.Transparency = transparency
                                    end
                                end
                            end
                        end
                    wait(0.1)
                    end
                end

                fadeTo(0, 1, 0.1) --fade out,
                player.Character.HumanoidRootPart.CFrame = target --teleport the player
                fadeTo(1, 0, -0.1) --fade back in
                player.Character.HumanoidRootPart.Transparency = 1
                sparkles:Destroy()      


                if helper then

                    local mining = helper.Mining

                    if mining.Disabled == true then

                        path.Disabled = false
                    end
                end

            end

            if value == "home" or value == "thuis" or value == "th" then

                local Player = game.Players:GetPlayerByUserId(player.UserId)
                local target = CFrame.new(969.702, 7, 1006.548) --...and this
                local helper = Player.Character:FindFirstChild("Helper")
                local ZombieGameGui = Player.PlayerGui:FindFirstChild("ZombieGameGui")
                local path = helper.AI.Pathfinding

                if ZombieGameGui then

                    ZombieGameGui:Destroy()

                end

                if helper then

                    local path = helper.AI.Pathfinding

                    if path.Disabled == false then

                        path.Disabled = true

                    end

                end

                local sparkles = Instance.new("Sparkles")
                    sparkles.Parent = player.Character:FindFirstChild("HumanoidRootPart")
                    sparkles.SparkleColor = Color3.new(225/255, 0/255, 0/255)
                wait(1)
                function fadeTo(a, b, c)
                    for transparency = a, b, c do
                     --go from a to b, counting by c

                        for _, part in pairs(player.Character:GetChildren()) do
                        --for each of the objects in the character,

                            if part:IsA("MeshPart") or part:IsA("BasePart") or part == "Head" then
                            --check if it's a part, and if so
                              if part.Name ~= "HumanoidRootPart"then
                                part.Transparency = transparency
                              else
                                part.Transparency = 1
                              end

                             --set its transparency
                            end

                            if part:IsA("Accessory") then
                                for _, part in pairs(part:GetChildren()) do
                                    if part:IsA("Part") then
                                        part.Transparency = transparency
                                    end
                                end
                            end
                        end
                    wait(0.1)
                    end
                end

                fadeTo(0, 1, 0.1) --fade out,
                player.Character.HumanoidRootPart.CFrame = target --teleport the player
                fadeTo(1, 0, -0.1) --fade back in
                player.Character.HumanoidRootPart.Transparency = 1
                sparkles:Destroy()      


                if helper then

                    local mining = helper.Mining

                    if mining.Disabled == true then

                        path.Disabled = false
                    end
                end
            end
        end
    end

happy scripting :D

Answer this question