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

[SOLVED] for i, v in ipairs loop only printing/teleporting one player?

Asked by 4 years ago
Edited 4 years ago

Hey all, I'm working on a minigame script and my loop only teleports one player. I've tried many different solutions and researched many times but no luck.

I tried using the same for loop in another script and it prints out multiple players (only in a while loop). However, this one only prints out one player and not the rest.

for i, v in ipairs(game:GetService("Players"):GetChildren()) do
            print(i,v) --only prints out one player
            local name = v.Name
            local check = workspace:FindFirstChild(name) 
            if check then
                local humanoid = v.Character:FindFirstChild("Humanoid")
                if humanoid then
                    v.Character:MoveTo(spawns[i].Position) --only one player teleports
                    local InGame = v.InGame
                    InGame.Value = true 
                    TimeUntilEnd(GameTimer) 
                    local points = v.leaderstats.Points
                    local wins = v.leaderstats.Wins
                    -- wins and losses
                    if InGame.Value == true then
                        print("you win")
                        table.insert(winTable, name)
                        points.Value = points.Value + 50
                        wins.Value = wins.Value + 1
                    else
                        print("you lost")
                    end
                end
            end
        end
0
You tested it in studio? if so, there will be only you in studio Soban06 410 — 4y
0
I tested it with multiple players in game, and multiple test players in studio. sidewinder44 20 — 4y
0
If this code runs as soon as the server starts there will only be one player in the game as it run Spjureeedd 385 — 4y
0
I'll try delaying the while loop for the minigame, maybe that'll solve it. I don't know what else would cause it. sidewinder44 20 — 4y
0
Figured out the issue. sidewinder44 20 — 4y

Answer this question