Create a list of players based on a bool value

I’m trying to create a list of players still playing based on a boolean value that I have saved inside the player. With my current code no players are being put into the list. I’ve looked around for a solution but I couldn’t find anything.

Code:


game.Players.PlayerAdded:Connect(function(player)
	local values = Instance.new("Folder", player)
	values.Name = "values"

	local playerPlaying = Instance.new('BoolValue', player)
	playerPlaying.Name = "playing"

	playerPlaying.Parent = player.values
	
	player.CharacterAdded:Connect(function(Char)
		Char.Humanoid.Died:Connect(function()
			playerPlaying.Value = false
		end)
	end)
end)

local playersPlaying = {}
		
for i, player in pairs(game.Players:GetChildren()) do
	if player.values.playing == true then
		table.insert(playersPlaying, player.Name)
	end
	
	if #playersPlaying <= 1 then
		gameTime = 1
	end
end
1 Like

It seems that there may be a couple issues. In your if statement when you’re checking if the boolean is true, you forgot to write

player.values.playing.Value

You also may need to initialize the default value for playing to true when the character is added to the game.

Hope this helps!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.