Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 8 years ago

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!

0
"PossiblePositions" I am assuming is table of positions? fishguy100 135 — 8y
0
Yes docrobloxman52 407 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago

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)
Ad
Log in to vote
1
Answered by
joalars2 107
8 years ago

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

Answer this question