"Hostiles" is not a valid member of teams

So I’m currently creating a raid system, and the one thing I need to finish is the tracking for how many players are in each team. I currently have this working for joining the team, where the hostiles and friendly team values get incremented, but the system I am making creates the teams automatically when its started. Because of this, when the game starts, the following code returns the error that the “Hostiles” or “Friendly” team is not a valid member of Teams (for obvious reasons because it doesn’t exist yet until its started).

Is there any way to make these connect functions wait until the teams are created until running? I tried to encapsulate this inside of a while loop when the teams are created, but this ended up crashing my studio.


			print("left h")
			if variableSet1.hostileCounter.Value > 0 then
				variableSet1.hostileCounter.Value = variableSet1.hostileCounter.Value - 1

			print("left f")
			if variableSet1.friendlyCounter.Value > 0 then
				variableSet1.friendlyCounter.Value = variableSet1.friendlyCounter.Value - 1
1 Like

Try a

repeat wait() until game:IsLoaded()

at the very beginning of the code.

Waiting until the game is loaded wouldn’t work because the teams don’t get made when the games loaded, it’s made once the “raid” gets started through a GUI

So instead of game:IsLoaded() do Teams.WaitForChild(“Hostile”)

1 Like

I literally just realised when I tried this I put game.teamService after I defined teamService. Doing what you said did work though.

1 Like