I have cloned a part to workspace inside a folder named mapHolder. Anyways there are spawns in there that I am trying to make every player teleport to, however, this will not work and there are no errors.
Teleport code:
-- this code should teleport a player to a random spawn part on the map -- mapSelected is a string value which indeed holds the name of the map function teleportPlayers() for i,v in pairs(allPlayers) do wait() if allPlayers[v] ~= nil then print("Player is there") if allPlayers[v].Character ~= nil then print("Character is there") if allPlayers[v]:FindFirstChild("Humanoid").Health ~= 0 then print("Player is alive") local mapSpawns = mapHolder[mapSelected.Value]:FindFirstChild("Spawns"):GetChildren() allPlayers[v].Character:FindFirstChild("HumanoidRootPart").CFrame = mapSpawns[math.random(1, #mapSpawns)].CFrame-- + Vector3.new(0, 3, 0) end end end end end
On this line,
if allPlayers[v] ~= nil then
You are trying to do allPlayers[Player] instead of the index of the player in the table.
It should be either just v or allPlayers[i] like this,
function teleportPlayers() for i,v in pairs(allPlayers) do wait() if v ~= nil then print("Player is there") if v.Character ~= nil then print("Character is there") if v:FindFirstChild("Humanoid").Health ~= 0 then print("Player is alive") local mapSpawns = mapHolder[mapSelected.Value]:FindFirstChild("Spawns"):GetChildren() v.Character:FindFirstChild("HumanoidRootPart").CFrame = mapSpawns[math.random(1, #mapSpawns)].CFrame-- + Vector3.new(0, 3, 0) end end end end end