How do I hide a frame that depends on the number of players in a team?

Hello, I’m scripting a custom playerlist and I’d like to hide teams which have no players in it. Problem is I don’t understand how to code it: I can’t find a way to link the frame and the actual team.

I’ve searched around for a solution but can’t find any, if someone could help it would be amazing, thank you in advance.

Here’s some code and photos:

(NonInUsoTeam is the folder in ReplicatedStorage where I want the frames to be stored)

if #team:GetPlayers() == 0 then
    local frames = listaplayer:GetChildren()
    if frames.Name == team.Name and #team:GetPlayers() == 0 then
        frames.Parent = game.ReplicatedStorage.NonInUsoTeams
    end
end

This if is in a for loop, I’ve tried with a print and it prints the number of the teams with players missing.

listaplayer is the ScrollingFrame where all the frames are.
(local listaplayer = script.Parent.Frame.ScrollingFrame)

GUI: https://gyazo.com/033e4c8e17bb0802251f868d235380c1

(The local script in it is a Canvas Size thing of the scrolling frame, nothing to do with the actual script)

The name of the frames are equivalent to the names of the teams in the Teams Service.

If you need the entire block of code, let me know.

Instance:GetChildren() returns an array that contains the children of the instance. The array doesn’t have a key “Name”, although each child in it does, so you are comparing nil to the name of the team. You could use a loop to compare the name of each frame in the array to the name of the team. However, I’d recommed this instead:

if #team:GetPlayers() == 0 then
    local frame = listaplayer[team.Name]
    frame.Parent = game.ReplicatedStorage.NonInUsoTeams
    end
end
1 Like

Thank you it worked, but when I try to change again teams I get this error, even after making changes to the script:

I need to do :re me with admin commands in order to make it work.

	if #team:GetPlayers() <= 0 then
		local frame = playerlist[team.Name]
		frame.Parent = game.ReplicatedStorage.NonInUsoTeams
	elseif #team:GetPlayers() >= 1 then
		frame.Parent = playerlist
	end


https://gyazo.com/ee8af484f06a983d21026c80957eb7ed

SOLUTION I fixed it by putting a wait(0.5) at line 70. Thank you really much for helping.

1 Like