#team:getplayers() doesnt go to 0 even if there is no one in specified team

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I want the script to break out of first ‘if’ statement if someone leaves the team and move to second ‘if’ statement

  1. What is the issue? Include screenshots / videos if possible!

It does move to second ‘if’ statement in the beginning but after i join other team, it still counts me in the team i just left

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    tried to find the solution but cant find any similar topics somehow

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

so i am working on a small round based game and i found this problem where if a person gets added to the ‘playing’, script counts that person but if that person leaves the ‘playing’ team and joins ‘lobby’ team, script doesn’t lower the amount of players in ‘playing’ team. if i cant fix this then game wont end if there is only one person alive in ‘playing’ team. First time posting here so i hope formatting and my explaination isn’t hard to understand

while true do 
	local TEAMS = game:GetService("Teams").Playing:GetPlayers()
	local numberofplayers = #TEAMS
	wait(1)
		if 	numberofplayers >= 1 then
			print(numberofplayers .. " There is one person in playing team")
		end
		if numberofplayers == 0  then
			print(numberofplayers .. " There is no one in playing team")
		end 


end

While this isn’t the way I’d write this script it’s working for me.

image

image

I’m going to assume you’ve either got the team’s name wrong or you’re setting the player’s team on the client-side via a local script which means that the player’s team change won’t replicate to the server.

1 Like

does it work when you leave team after joining it? i mean it should print there is no one in playing team again after you leave the playing team but it keeps printing ‘there is one person in playing team’ instead of that

edit: oh wait yes im changing the player’s team from local script! let me try again

yess thanks alot, made a server script and everything seems to be working.