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
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.
: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
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).
The one below is when the ones alive are transferred to PlayerWaitingFolder, and then the ones dead go to PlayerIngameFolder when the intermission ends.
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.