PlayerList teams not removing and adding [SOLVED]

So I’m trying to make a playerlist gui that when no player is on the team, it removes the team frame and when a player is on the team, it adds back the team frame.

The script sometimes with certain teams works, and then doesn’t. Any help?

I’ve gotten some code from this post right here which helped me a little bit.

CODE DELETED

Solved it cause I have a huge brain.