Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

This part of my code isn't teleporting the players?

I can't figure out why this part in my script isn't working when it tries to teleport all players to the map. What it does is insert all the players into a table then I use a for loop to get all the players in the table. Then, whenever I assign each player a spawn to be teleported to, it just doesn't teleport them and gives no error.

	--insert players into table
	for _, player in pairs(game.Players:GetPlayers()) do
	    table.insert(_G.gamePlayers, player)
	end

	--teleport players
	for _, player in pairs(_G.gamePlayers) do
	    local spawns = randomMap:FindFirstChild("Spawns"):GetChildren()

	    if #spawns > 0 then
	        local head = player.Character:FindFirstChild("Head")
			local allSpawns = spawns[math.random(1, #spawns)]
	        local randomSpawn = table.remove(spawns, math.random(#spawns))

	        if head and randomSpawn then
	            head.CFrame = CFrame.new(randomSpawn.Position + Vector3.new(0, 2, 0))
	        end
	    end
	end

1 comment

0

can you show me the entire script.

1 answer

Instead of lines 4-12 just use table.remove on the global table to remove the player that died.

-- Im on mobile so excuse my lack of indentation

for i, v in pairs (_G.gamePlayers) do
if v == player then
table.remove(_G.gamePlayers, i)
end
end

2 comments

0

replace lines 4-12 on the second script with ^

0

oh and the reason what script wasnt working was because you didnt add a capital p to gamePlayers on line 12

This discussion is preserved as it was. New answers, comments, and votes are closed.