I am trying to make a** teleportation script** that will teleport all of the players to a random spawn location on my map. The 'map' variable is already defined earlier in the script. My error is: attempted to index field 'Character' (a nil value)
local MapPlayerSpawns = map.SpawnLocations:WaitForChild("PlayerSpawns"):GetChildren()
function tp()
local Players = game.Players:GetPlayers()
for i = 1,#Players do
local randomPTP = math.random(1,#MapPlayerSpawns)
local IndSpawn = MapPlayerSpawns[randomPTP]
Players[i].Character.HumanoidRootPart.CFrame = IndSpawn + Vector3.new(0,5,0) -- I get my error on this line.
end
end
tp()

7 comments
I did that and the error doesn't appear again but now I get a yellow/orange error saying: Infinite yield possible on 'Players.N43FGXL:WaitForChild("Character")'
Try that
attempt to index local 'plr' (a nil value) | Now I get this error...
Updated
Still get error...
This script works fine for me. It's probably your internet acting up.
My plr variable was displaying as 'nil'. I now fixed it. Thanks for help, I'll still accept your answer.