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)
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)
Right try this :
The remove the Vector3.new at line 13. And just leave one of the "(". That should work.