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

player.Character:MoveTo(pos) not working?

Asked by 9 years ago

I am trying to make each player teleport to their respective position on the map when they join, however, it is not working. Is there anything that I'm doing wrong? Script:

game.Players.PlayerAdded:connect(function(player)
    print ("[MainScript] Setting up player "..player.Name)

    for _,factory in pairs(game.Workspace.Factories:GetChildren()) do
        local isOwnedBy = factory.OwnerName
        local factoryNumber = factory.FactoryNumber
        local spawnPos = factory.SpawnPoint.Position

        if isOwnedBy.Value == "" and player.FactoryNumber.Value == 0 then
            player.FactoryNumber.Value = factoryNumber.Value
            isOwnedBy.Value = player.Name
            player.CharacterAdded:connect(function(character)
                    player.Character:MoveTo(Vector3.new(factory.SpawnPoint.Position) + Vector3.new(0, 1, 0))    
                end)            
        end
    end     

end)

2 answers

Log in to vote
1
Answered by
iaz3 190
9 years ago

Why player.Character when you have the character variable from the CharacterAdded event? also on line 13 you have "factory.SpawnPoint.Position" but a variable called "spawnPos" that equals "factory.SpawnPoint.Position"

This should work.

game.Players.PlayerAdded:connect(function(player)
    print ("[MainScript] Setting up player " .. player.Name)

    for _,factory in pairs(game.Workspace.Factories:GetChildren()) do
        local isOwnedBy = factory.OwnerName
        local factoryNumber = factory.FactoryNumber
        local spawnPos = factory.SpawnPoint.Position

        if isOwnedBy.Value == "" and player.FactoryNumber.Value == 0 then -- i believe "" is the same as nil
            player.FactoryNumber.Value = factoryNumber.Value
            isOwnedBy.Value = player.Name
            player.CharacterAdded:connect(function(character)
                    character:MoveTo(spawnPos + Vector3.new(0, 1, 0))    
                end)            
        end
    end     
end)

0
I don't know why, but the player is not being moved to the place I specify him. Tytanlore 15 — 9y
0
Where do you want him moved, and where does he move? Does it move to ANY factory? iaz3 190 — 9y
Ad
Log in to vote
-2
Answered by
iLegitus 130
9 years ago

Right try this :

The remove the Vector3.new at line 13. And just leave one of the "(". That should work.

0
Didn't work. Tytanlore 15 — 9y
0
Oh also remove the +Vector3.new(0, 1, 0) basically remove EVERY single vector3 in line 13. iLegitus 130 — 9y
0
Still doesn't work. Tytanlore 15 — 9y
0
Do this: "player.Character:MoveTo(factory.SpawnPoint.Position + Vector3.new(0,1,0))" instead. (Without quotes) Perci1 4988 — 9y

Answer this question