That could work. Lemme try it first.
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.
Oh wait you edited it I could try this
No no no. I disabled the part when the game automatically loads the characters when the player loads in.
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
@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.
Are 3 of them even loaded? add a print statement that runs whenever the Player:WaitForChild('Loaded').Value
statement is satisfactory
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
@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.
Well then maybe the 3rd player is loading after the code has ran
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.
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.
Maybe that’d work. I’m not on PC right now so I’ll try it tomorrow.
I gotta sleep now so cya tomorrow.
verify the value of loaded by printing it. 3rd players must not be getting set loaded==true
I would try changing that to >= just to see if it magically works.
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.