How would I loop through all players and get the name of a player with a boolvalue thats true?

I have this script, did not expect it to work, and it did not. I am not really sure where to start on this one.

local children = game.Players:GetChildren()
		for i = 1, #children do
			if children[i].istagged.Value == true then
				print(children.Name)
			end
		end

It prints nil, which is kind of expected. Not sure how to script this, what I want the script to do is loop through all players until it finds a player with the boolvalue that’s true, then it would et the name and that’s the person who would lose the game. But how would I find who has the boolvalue that’s set to true?

for _,plr in ipairs(game.Players:GetChildren()) do

	if plr.istagged.Value == true then
		print(plr.Name)
	end
	
end
1 Like
for _,v in pairs(game.Players:GetChildren()) do
	
	if v.istagged.Value then
		
		print(v.Name)
		
	end
	
end

I think this should work.

1 Like

where is the value located? inside the character?

for index,player in next,game.Players:GetPlayers() do
  if player.istagged.Value then
     print(player.Name)
  end
end

fastest way to do it.

for _, player in ipairs(game.Players:GetPlayers()) do
	local tag = player:FindFirstChild("istagged")
	if tag then
		if tag.Value then
			print(player.Name
		end
	end
end

Use :GetPlayers() instead of :GetChildren() (in case something that isn’t a player instance is parented to the player’s service). Additionally, you don’t need to do == true, the value of the “Value” property itself will be either true or false.

Hey is there a way to check if all players in the game have their boolvalues set to true. Im trying to make it loop through all players and if ALL players have a value set to true then a gui appears but i cant get it to work for alll players only 1, please help! @ZombieCrunchUK