Help with Displaying Children on GUI

I’ve been trying to make a little timer system to show the amount of children in a specific folder. However, these children are the players themselves. There are two folders, one for the ones alive (Ingame) and one for the ones dead (waiting). When displaying, it only shows the number 0 no matter the number of children inside the folder. What is the problem? Thanks in advance!

local time = 5
local gui = script.Parent
local folder = workspace.PlayerIngameFolder
local count = 0
gui.Text = time

while true do
	if time ~= 0 then
		time -= 1
		wait(1)
		gui.Text = time
		folder.ChildAdded:Connect(function()
			count += 1
		end)
		folder.ChildRemoved:Connect(function()
			count -= 1
		end)
	elseif time == 0 then
		gui.Text = "Round Ended! " .. count .. " winners!"
		print(count)
		wait(3)
		gui.Text = "Intermission.."
		wait(3)
		gui.Text = "Round Starting"
		wait(3)
		time = 5
		gui.Text = time
	end
end
1 Like

currently the count variable is only updating when a child is added or removed, which doesn’t consider the children already in the folder
to get the number of children in the folder try this:

local time = 5
local gui = script.Parent
local folder = workspace.PlayerIngameFolder
local count = 0
gui.Text = time

while true do
	if time ~= 0 then
		time -= 1
		wait(1)
		gui.Text = time
		count = #folder:GetChildren()
	elseif time == 0 then
		gui.Text = "Round Ended! " .. count .. " winners!"
		print(count)
		wait(3)
		gui.Text = "Intermission.."
		wait(3)
		gui.Text = "Round Starting"
		wait(3)
		time = 5
		gui.Text = time
	end
end```

Didn’t work. Still displayed 0. I’ve done that multiple times too, with different variations. I’ve also gotten to use the Assistant AI, but to no avail.

i feel like i’m missing something here, you’re absolutely certain that the folder has children visible to the client right

Yes. I’m completely sure that the folder has children visible.

image
Even does it for the waiting.

image

1 Like

:GetChildren() returns a table, and #table outputs the amount of items the table has. Therefore for the count, you could just do #workspace.PlayerIngameFolder:GetChildren()

This is how I would personally approach this, let me know if it helped.

local time = 5
local gui = script.Parent
local folder = workspace.PlayerIngameFolder
gui.Text = time

while true do
	if time ~= 0 then
		time -= 1
		wait(1)
		gui.Text = time
	elseif time == 0 then
		gui.Text = "Round Ended! " .. #workspace.PlayerIngameFolder:GetChildren() .. " winners!"
		print(count)
		wait(3)
		gui.Text = "Intermission.."
		wait(3)
		gui.Text = "Round Starting"
		wait(3)
		time = 5
		gui.Text = time
	end
end

This sadly did not help, the same result (count showing zero) occurs. I don’t know what the problem really is.

How are you parenting the players to the folder? Are you parenting them in a server script?

Just a normal script.
image

So how exactly do you change the parent of the players to the folder? The timer script does not do it from what I see. Do you use another script or do it manually?

A different script. The one below is when the player dies (transfers to PlayerWaitingFolder).
image
The one below is when the ones alive are transferred to PlayerWaitingFolder, and then the ones dead go to PlayerIngameFolder when the intermission ends.
image

These are both client scripts. Changing the parent of the player’s character in a client script will not replicate to the server which is what causes your issue. Your timer script is a server script and on the server there are no instances within the folder due to the reason explained in the previous sentence.

Oh. Thanks for helping me with the mistake. Should I change the server script to a local script?

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