I have 15 spawns in my game, each named "1" through "15", respectively, stored in a Folders object named SpawnLocations.
This is the corresponding code:
local REQUIRED_PLAYERS = 1
game.Players.PlayerAdded:Connect(function(player)
for n, player in pairs(game.Players:GetPlayers()) do local playerTable = {} local n = 1 playerTable[n] = player n = n + 1 end if game.Players.NumPlayers == REQUIRED_PLAYERS then for n = 1, 1 do player:LoadCharacter() player.Character.PrimaryPart.Position = game.Workspace.SpawnLocations[tostring(n)].Position end end
end)
The problem that arises, is that when I go to test this via server, the player joins, but spawns at spawn #6, instead of spawn #1. Also, his head falls off.
I am unsure where the code in incorrect, but I'm willing to hear all suggestions.
You didn't describe exactly what the code is supposed to do, so I made a guess:
local Players = game:GetService("Players") local SpawnLocations = workspace.SpawnLocations local i = 1 Players.CharacterAutoLoads = false Players.PlayerAdded:Connect(function(Player) Player.RespawnLocation = SpawnLocations[i] -- Assign new Player to a Spawn i = i + 1 Player:LoadCharacter() end)