I am trying to make a script that will teleport players to a random 'spawn' location within a map. The 'map' variable is already defined earlier in the script. (This is a chunk of my larger script)
local MapPlayerSpawns = map.SpawnLocations:WaitForChild("PlayerSpawns"):GetChildren()
function tp()
local Players = game.Players:GetPlayers()
for i,v in pairs(Players) do
local randomPTP = math.random(1,#MapPlayerSpawns)
local IndSpawn = MapPlayerSpawns[randomPTP]
wait(0.1) -- For loading times
local plr = Players[i]
plr:WaitForChild("Character"):SetPrimaryPartCFrame(IndSpawn.CFrame + Vector3.new(0, 5, 0)) -- Script works but doesn't teleport the player.
end
end
tp()
Note: This isn't a duplicate question, I asked a different question with a similar script earlier.
I hope you can help me.

4 comments
You can Find A Random Map By Just using "MapPlayerSpawns[math.random(1,#MapPlayerSpawns)" lol! that will return 1 Random Spawn From the Map Specificaly, so get rid of line 5 and 6 and replace it with that!
I know, but that doesn't solve my problem.
It doesnt?
Of course it doesn't, he is already doing that just with two variables instead of one line.