It loads two players, but doesn't load the third one?

That could work. Lemme try it first.

1 Like

Hey, I remember you from that one post about a tween train system lagging, I’m actually making a train system right now, anyways back to the point. I think you could do something like this:

local Players = game:GetService('Players')

local game_running = false --// You can change this variable when needed

coroutine.wrap(function()
    while wait() do
        if #Players:GetPlayers() > 1 then
            if not game_running then
                 game_running = true
                 
                 for i, Player in pairs(Players:GetPlayers()) do
                     local Character = Player.Character

                     if Character then
                         --// do what you want here.
                     end
                 end
            end
        end
    end
end)()

I’m using a coroutine here in case you need to do other stuff with the script

Same thing happens, I tried printing, it does print 1 and 2 when the players start loading in.
When the third one loads, it kinda stops the loop.

1 Like

Oh wait you edited it I could try this

1 Like

No no no. I disabled the part when the game automatically loads the characters when the player loads in.

1 Like

If you’re making something like a minigame system, I suggest you do something like so

local Players = game:GetService('Players')
local ServerStorage = game:GetService('ServerStorage')

local GameRunningValue = ServerStorage:WaitForChild('GameRunning') --[[have a bool value in the server storage 
that tells if the game is running]]

while true do
    if #Players:GetChildren() <= 1 then
        --[[ this part checks if there aren't multiple people and if so,
 loop and wait until that's not the case anymore]]
        while #Players:GetChildren() <= 1 and wait() do end
    end

    for i, Player in pairs(Players:GetChildren()) do
        if Player:WaitForChild('Loaded').Value then
            Player:LoadCharacter()
        end
    end

    GameRunningValue.Value = true
    workspace.Music:WaitForChild("MainMusic"):Play()

    while GamingRunningValue.Value and wait() do
        --[[Do the game here, if the game ends, set the value to false
            and it will exit this loop]]
    end

   --// If the loop above stopped because the game ended, this will loop back to the top of the main loop
end
1 Like

@BowlerAr But I’m trying to check if there are 2 or more players. If there are 3 players, then three of them should have their characters loaded. But the problem is it only calls LoadCharacter() on two players even if there are three loaded.

1 Like

Are 3 of them even loaded? add a print statement that runs whenever the Player:WaitForChild('Loaded').Value statement is satisfactory

1 Like

Btw this is unrelated, but for my train system the lag only occurs when the train goes too fast so I’m making the game scaled down (and i have a script that scales the players down as well) and I just divide the speed

1 Like

@BowlerAr I’m sure they are loaded, I even checked from the explorer, took a look on every Loaded bool, it has been set to true.

In a separate script, whenever a player joins, an Instance is created which is bool value, then name it Loaded and set it to true.

1 Like

Well then maybe the 3rd player is loading after the code has ran

1 Like

First of all I use the thing in roblox studio where you can go “multiplayer mode” and choose how many players you want.

Pretty sure all three of them are loaded at the same time. But the script doesn’t notice that Player3 has been loaded too. Resulting that player 1 and 2 characters are loaded only.

1 Like

Hmmm, maybe add a wait(10) at the start of the script, also roblox studio test mode is slower than the roblox player, especially with mutliple clients.

1 Like

Maybe that’d work. I’m not on PC right now so I’ll try it tomorrow.

1 Like

I gotta sleep now so cya tomorrow.

1 Like

verify the value of loaded by printing it. 3rd players must not be getting set loaded==true

2 Likes

I would try changing that to >= just to see if it magically works.

2 Likes

It works if 2 players loaded. Besides, if you change it to >=, you will have to change the interger to 2, so there’s no point.

Everything’s now alright. The way I fixed it, it’s complicated. It’s a long story. Thanks for helping everyone.