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

When getting all the players it only gets the first player that joins the server?

Hi, in my game script I have multiple sections where I need to get all the players in the game. But with my script it only gets the first player that joins the server. Can you please help? Here's a part of the script where it gets the first player that joins the server:

	for i, player in pairs (Game.Players:GetChildren()) do
		if player.Character and player.Character:FindFirstChild("Torso") then
			player.Character.Torso.CFrame = SpawnPositions[math.random(1, #SpawnPositions)] + Vector3.new(0, i * 5 ,0)
			Game:WaitForChild("ReplicatedStorage")
			local bomb = Bomb:Clone()
			bomb.Parent = Game.Workspace
			Game.Workspace.bomb.Position = PossiblePositions			
		end

Everything here is defined

If you could help that would be amazing!

2 comments

0

"PossiblePositions" I am assuming is table of positions?

0

Yes

2 answers

✓ Accepted answer

Maybe try adding the players to a table as they enter like this:

local PlayerTable = {}


game.Players.PlayerAdded:connect(function(Player)
	PlayerTable[#PlayerTable + 1] = Player
end)

You're only searching it once. Try adding a loop.

Unless its in a minigames-ish script, in which case i cant see the error

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