Ummm not much to say other than i want to teleport all Players in the global table called _G.Players but if i insert it there

for _, player in pairs (_G.Players) do
    if player and #spawns > 0 then
        local torso = player.Character:WaitForChild('HumanoidRootPart')
.
.
.

it will give me a Error that Character is a nil value

but if I do it like this

for _, player in pairs (game.Players:GetPlayers()) do
    if player and #spawns > 0 then
        local torso = player.Character:WaitForChild('HumanoidRootPart')

Everything works without errors but i dont want that. because it would teleport all Players that are currently in the game. I just want to teleport the Players inside the _G.Players Table. Any solution for that? Here is my whole teleport script if you need it

	--Teleport tributs
	local spawns = map:WaitForChild("Spawns"):GetChildren()
for _, player in pairs (game.Players:GetPlayers()) do
    if player and #spawns > 0 then
        local torso = player.Character:WaitForChild('HumanoidRootPart')
        local allspawns = math.random(1, #spawns)
        local randomspawn = spawns[allspawns]
        if randomspawn and torso then
            table.remove(spawns, allspawns)
            torso.CFrame = CFrame.new(randomspawn.Position + Vector3.new(0,2,0))
		end
	end
end

4 comments

0

Don't use _G, use whatever script is creating _G.players to teleport them instead and do player.Character or player.CharacterAdded:Wait() followed up with your HumanoidRootPart line

0

This doesnt help me much.

0

line 3 -> char = player.Character or player.CharacterAdded:Wait()....line 4 -> char:WaitForChild("HumanoidRootPart")

0

Such an edit runs the risk of teleporting people mid-round though, maybe it would be better to just check if the character is spawned in already?