Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

player.Character:MoveTo(pos) not working?

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

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)

2 comments

0

I don't know why, but the player is not being moved to the place I specify him.

0

Where do you want him moved, and where does he move? Does it move to ANY factory?

Right try this :

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

4 comments

0

Didn't work.

0

Oh also remove the +Vector3.new(0, 1, 0) basically remove EVERY single vector3 in line 13.

0

Still doesn't work.

0

Do this: "player.Character:MoveTo(factory.SpawnPoint.Position + Vector3.new(0,1,0))" instead. (Without quotes)

This discussion is preserved as it was. New answers, comments, and votes are closed.