if game.Players.NumPlayers < 2 then for i, v in pairs(game.Workspace:GetChildren()) do if v:FindFirstChild("HumanoidRootPart") then if v:WaitForChild("IsLoading").Value == true then status.Value = "There needs to be 1 more player to begin!" end end end end
The script goes past the first 2 lines but then it gets stuck when it checks for the HumanoidRootPart
. It gets get stuck in a way that even if it reads over a player, it doesn't go past the if statement. There is no error and I don't know what to do so I need your help!
If you want a player's character, do player.Character
. If you have a model and want to know if it's a player's character, do game.Players:GetPlayerFromCharacter(model)
. In your case, it looks like you want to know the number of players that have an IsLoaded
boolean value that is set to true
.
Notes about your current script:
>= 2
on the first line?WaitForChild
in a for
loop - imagine if IsLoading is never added (ex maybe the player leaves or a script breaks) and WaitForChild never returns? Instead, use FindFirstChild
, assigning the result to a local variable.status.Value
every time you find an IsLoaded
value that is true. Is Recommended script:
function GetNumPlayersLoaded() local p = game.Players:GetPlayers() local char, isLoaded local num = 0 for i = 1, #p do char = p[i].Character isLoaded = char and char:FindFirstChild("IsLoaded") if isLoaded and isLoaded.Value then num = num + 1 end end return num end if GetNumPlayersLoaded() < 2 then status.Value = "There needs to be 1 more player to begin!" end
Notes about this script:
game.Players:GetPlayers()
so that it will only get actual players rather than all children that happen to be in game.Players (though usually this is the same thing)IsLoaded
value in their character, it is assumed that they are not ready