How do I detect if a team has no players constantly?

This should work, but its not. This is a server script in ServerScriptService

Im trying to get it to constantly check if the Manager team has no players.

local Teams = game:GetService("Teams")
local team = Teams.Manager

if Teams.Manager:GetPlayers() == 0 then
	game.Workspace.ManagerGiver.ProximityPrompt.Enabled = true	
end

maybe try

local Teams = game:GetService("Teams")
local team = Teams.Manager

if #team:GetPlayers() == 0 then
	game.Workspace.ManagerGiver.ProximityPrompt.Enabled = true	
end

1 Like

Nope, nothing.

I even tried attaching a while loop to it and it still didnt work.

You should use events instead as this can cause lag on the server which can cause data to load in slower

local Teams = game:GetService("Teams")
local team = Teams.Manager

while wait(1/rateOfChecksASecond) do
if #Teams.Manager:GetPlayers() == 0 then
	game.Workspace.ManagerGiver.ProximityPrompt.Enabled = true	
end
end
1 Like

sorry i wrote it wrong the first time i meant, instead do

local Teams = game:GetService("Teams")
local team = Teams.Manager

if #team:GetPlayers() == 0 then -- I had get children instead of getplayers
	game.Workspace.ManagerGiver.ProximityPrompt.Enabled = true	
end
1 Like

Im sure this one works too but I havent checked.

(incase someone else goes on this topic looking for answers)

local Game = game
local Teams = Game:GetService("Teams")
local Team = Teams.Team

local function OnTeamPlayerRemoved(Player) --'Player' that left the team.
	if #Team:GetPlayers() == 0 then
		--Do code.
	end
end

Team.PlayerRemoved:Connect(OnTeamPlayerRemoved)

https://developer.roblox.com/en-us/api-reference/event/Team/PlayerRemoved

1 Like