Problem with finding a winner in round system

Hi. My script is meant to keep seeing how many players are in the alive team while the boolValue “inRound” is true. When there is 1, it should print ‘we have a winner,’ but it doesn’t seem to be working. There are no errors in the output.

local Teams = game:GetService("Teams")
while inround.Value == true do
	wait(0.1)
	local teamPlayers = Teams["Alive"]:GetPlayers()
	local aliveCount = #teamPlayers
	
	if aliveCount == 1 then
	print("we have a winner")	
		
	end
end

2 Likes

I think you can use local “teamPlayers”(line 4) for get all players in team(Maybe need use loop “For”)

1 Like

The inRound value can be set to false and stop the loop from running entirely, use a while true do loop and check if the value is true (will cause any code below it to not run as it yields, put it at the end of the script if this matters):

while true do
	wait(0.1)
if inRound.Value == true then -- check
	local teamPlayers = Teams["Alive"]:GetPlayers()
	local aliveCount = #teamPlayers
	
	if aliveCount == 1 then
	print("we have a winner")	
	end
	end
end

You can used .Changed instead of a while loop

Have you tried further debugging such as Printing the number of players each loop to make sure the # of players is being received?

It will even be more complicated, you still need a while loop and will need to disconnect and reconnect the loop on Changed

I assume you have but have you checked if inround.Value is actually True, and if, was it set to True by the same sided script (local-local, global-global). Also check if the script is not disabled. :slight_smile:

I think they mean detecting when alive players change, not the in round value

2 Likes

Wouldn’t a while wait() loop work better to reduce lag?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.