How do i make a list of all players in a game? and Check their Health?

Is the script disabled? What’s your explorer hierarchy?

Why do you need the player Priority?

Just use the value “v”

Shhh, we dont talk about that lol. But also i get this error now “attempt to index field ‘Character’ (a nil value)”

1 Like

OH! that means the player Character has not loaded yet just add this:

if v:WaitForChild("Character").Humanoid.Health < 1 then

Also why not doing?

 for i, v in pairs(game.Players:GetPlayers()) do
    	print(v)---players name
        print(v:WaitForChild("Character").Humanoid.Health).."/"..v:WaitForChild("Character").Humanoid.MaxHealth)
    end
1 Like

Noticed issues:

  1. Your only printing ‘mjvjhgk’ when health is less than 1.
  2. Your not actually printing the health itself, just checking if its less than 1.
  3. You haven’t accounted for a character not being there.

Amendments to your script:

for i, v in pairs(game.Players:GetPlayers()) do
	print(i) -- Order in List, this is not "priority" as you like to call it.
	print(v) -- Player instance, if you print this it wont return the name
	print(v.Name) -- Player instance's name
	if v.Character then -- if this doesn't pass for a player then a character for them has not been loaded yet.
		print(v.Character.Humanoid.Health) -- this will print the current health of a character.
	end
end

Recommended amendments:

for _, Player in pairs(game.Players:GetPlayers()) do -- Renamed variables to make code easier to understand.
	print(Player.Name) -- Player instance's name
	if Player.Character then -- if this doesn't fire for a player then a character for them has not been loaded yet.
		print(Player.Character.Humanoid.Health) -- this will print the current health of a character.
	end
end
1 Like

You can’t do

player:WaitForChild("Character")

Because the character isn’t a child of the player

2 Likes

USe character added event, to check when the char is spawned. Or do, repeat wait() until player.Character

I tried it and it gave me a falled to search error, so I added a wait time to the waitforchild and that errored too.

for i, v in pairs(game.Players:GetPlayers()) do
	print(i)---player priority
	print(v)---players name
	if v:WaitForChild("Character", 1).Humanoid.Health < 1 then
		print("Big boi in da house")
	end
end

First:
Please fix your boolean comparison of < 1.

Second:
Character is not really a child of player, its basically just a pointer. You can’t therefore use “WaitForChild”

Third:
If you don’t get it after 1 second → automatically returns nil / error.

Finally, please read as its probably a nicer solution for you:

1 Like

Because @starmaq was right, we cannot WaitForChild an Player Charracter

1 Like

Using the CharacterAdded event would not work in his instance, he wants them printed together through one script and not separately through many scripts.

Im Trying your suggestions but nothing in the Output screen is poping up

Are you checking Local logs or Server Side Logs?

In Studio both normaly act the same

What @6Clu is correct and would work, the only problem with it is it would ignore a player if he’s character hasn’t loaded yet, which is why nothing is being printed, so here is another suggestion.

for _, Player in pairs(game.Players:GetPlayers()) do
    print(Player.Name) -- Player instance's name 	
    local character = v.Character or v.CharacterAdded:Wait() --youll find yourself using this line a lot when waiting for a character to load
    print(character.Humanoid.Health)
end
2 Likes

this is getting some where thank you, i got the health value to pop up

1 Like

The Humanoid may or may not be inserted yet with CharacterAdded, best to use CharacterAppearanceLoaded since that fires when their full appearance (accessories, shirts etc) are loaded.

2 Likes

Thank you for the information, didn’t actually know that. But in this system it’s better to just wait for the character’s humanoid to load, waiting for the accessories is not nessacery it’s just gonna waste more time

1 Like
local Players = game.Players:GetChildren()

for i, v in pairs(Players) do
	print(i)---player priority
	print(v)---players name
	if v.LocalPlayer.Character.Humanoid.Health < 1 then
		print("Current Player Health Is"..v.LocalPlayer.Character.Humanoid.Health)
	end
end

This script may work…

The player is already there, no need to do v.LocalPlayer. And this is just the same problem with waiting for the character to load