Getting game to start on minimum amount of players with timer

I’m trying to start an event when there are two or more players on a team that they join by touching an object. Currently, I’m not getting any errors. The function works when you take out teamCount in the if statement.

The timer seems to work for 15 seconds however it is some reason all over the place and spamming numbers like this: When the touch function uses the LobbyTimer() function. (Timer is now fixed, however doesn’t work with teamCount still)

 11:36:06.703  Starting game in... 2  -  Server - GameOver:27
  11:36:06.937  Starting game in... 6  -  Server - GameOver:27
  11:36:06.970  Starting game in... 5  -  Server - GameOver:27
  11:36:07.286  Starting game in... 1  -  Server - GameOver:27
  11:36:07.437  116  -  Server - ChaosTiles:132
  11:36:07.704  Starting game in... 1  -  Server - GameOver:27
  11:36:07.953  Starting game in... 5  -  Server - GameOver:27
  11:36:07.986  Starting game in... 4 (x2)  -  Server - GameOver:27
  11:36:08.454  115  -  Server - ChaosTiles:132
  11:36:08.719  Starting game in... 4 (x2)  -  Server - GameOver:27
  11:36:09.469  114  -  Server - ChaosTiles:132
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GameMode = game.ReplicatedStorage.GameMode
local Status = game.ReplicatedStorage.Status
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local teamPlaying = Teams.InGame
local teamSpectators = Teams.Spectating

local function LobbyTimer()
	for i = LobbyWaitTime, 1, -1 do
		Status.Value = "Starting game in... ".. i
		wait(1)
		print(Status.Value)
	end
end

StartLocation.Touched:Connect(function(player)
	local player = game.Players:GetPlayerFromCharacter(player.Parent)
	player.Team = teamPlaying
	player.TeamColor = teamPlaying.TeamColor
	local teamPlayers = Teams.InGame:GetChildren()
	local teamCount = #teamPlayers
	LobbyTimer()
	if GAME_ACTIVE.Value == false then
		local GameModeSelect = math.random(0,0)
		if GameModeSelect == 0 and teamCount >= 2 then  --works without teamCount
			GameMode = 0
			GameStart:Fire()
		elseif GameModeSelect == 1 then
			GameMode = 1
			GameStart1:Fire()
		end
		GAME_ACTIVE.Value = true
	end
end)

How can I start the game with a minimum player count?

Whenever someone touches the part, it starts the timer, again. You’ll need to implement some sort of check so that two timers aren’t running at the same time.

I fixed that. The timer still worked in a sense and you would still go in game regardless. However, even fixing the timer I still can’t load in based on playerCount.

When the timer hits 0 for intermission, if it does not have enough of players then it makes a boolean value true and a script picks up on that and calls the function to loop again and deletes the boolean value.

1 Like

Sounds easy enough, I have one question though. I was worried if this was correct:
local Teams = game:GetService(“Teams”)
local teamPlaying = Teams.InGame

local teamPlayers = Teams.InGame:GetChildren()
local teamCount = #teamPlayers
local teamPlayers = Teams.InGame

Don’t get the children with a variable as it gets the old players in the game and not the new ones; so it doesn’t update.
Instead do this:

if #teamPlayers:GetChildren() > x then
    local teamCount = #teamPlayers:GetChildren()
end
1 Like

hm so it shows my player in the InGame team, however when I print #teamPlayers:GetChildren() it comes up at zero

Is the folder ever deleting itself? Also is it a localscript?

It’s a ServerScriptService script and the Teams folder doesn’t ever appear to be deleting itself after testing. Unless your referring to a separate folder there is none for the “InGame” team.

Could you show the script and/or explorer tab in a video?

team

There is nobody in the ‘InGame’ team folder.
Or is it a different folder?

1 Like

Oh, I didn’t realize that counted as a folder. It is not showing up in any other Folder. But it shows the character in the team under leaderboard.

Yes, so thats why. Its 0 because the character is not in the ‘InGame’ team ‘folder.’
Do fix this all you have to do is move the character over to that team.

1 Like

Makes sense, not sure why it shows the player is in team in leaderboard then. I also followed Roblox documentation to add to team, but it doesn’t quite work.

1 Like