Sarnaif Channel
Sarnaif Channel

Reputation: 9

Script doesn't move player to a part

I was trying to make player teleport to certain object on the map but it just can't!

I don't know what to try

local items = {"Coal Chunk Tool", "Diamon Tool", "Iron Ingot Tool", 
"RokakakaFruit Tool", "Gold Ingot Tool"}
for _, v in pairs(game.Workspace:GetChildren()) do
    for _, d in pairs(items) do
        if v.Name == d then
            wait(1)
            game.Players.LocalPlayer.Character:MoveTo(v.Position)
            print("tped")
        end
    end
end

my player just doesn't move

Upvotes: 1

Views: 1830

Answers (3)

Ross
Ross

Reputation: 128

Try using CFrame to move the player, we will need to use the HumanoidRootPart, so it moves the rest of the body!

See if this script makes a difference;

local items = {"Coal Chunk Tool", "Diamon Tool", "Iron Ingot Tool", "RokakakaFruit Tool", "Gold Ingot Tool"} for _, v in pairs(game.Workspace:GetChildren()) do for _, d in pairs(items) do if v.Name == d then wait(1) game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = v.CFrame print("tped") end end end

If you need any help, post questions in the comment section.

Ross.

Upvotes: 1

Chris Lallo
Chris Lallo

Reputation: 320

Here are some things you should note when using the :MoveTo() method (in case the other person confused you):

  • :MoveTo() called on a Humanoid will cause the player's character to walk towards its given destination
  • :MoveTo() called on a Model will teleport the player's character

To teleport their character then, you will have to call this method on their character model. Additionally, there's no need to nest the second for loop inside the first. Just check the table for the given value.

local items = {"Coal Chunk Tool", "Diamon Tool", "Iron Ingot Tool", "RokakakaFruit Tool", "Gold Ingot Tool"}

for _, v in pairs(game.Workspace:GetChildren()) do
    if items[v.Name] then
        wait(1)
        game.Players.LocalPlayer.Character:MoveTo(v.Position)
        print("tped")
    end
end

Upvotes: 1

Saldor010
Saldor010

Reputation: 71

Without looking at the rest of your code, the MoveTo function will only attempt to make your player walk over there. What you want to do is change the CFrame of the player's character.

game.Players.LocalPlayer.Character.Head.CFrame = CFrame.new(v.Position)

Upvotes: 1

Related Questions