Player count not reducing?

I’ve been making a round-based game, and I’ve been stuck on a countdown.

For some reason, when more people join, the countdown doesn’t reduce and I cannot for the life of me find the issue.

Server script:

local PlayersToStart = 5

local TwoTimesGhostGamepassID = 6395460

local RE = game.ReplicatedStorage.RemoteEvent

local MPS = game:GetService("MarketplaceService")

math.randomseed(tick())


wait(1)

while true do

local PlayerCount = #game.Players:GetChildren()

if #game.Players:GetChildren()< PlayersToStart then

RE:FireAllClients("KeyWord",PlayersToStart - PlayerCount .." Player(s) needed to begin a round!",true)

Local Script:

local RE = game.ReplicatedStorage.RemoteEvent

local Player = game.Players.LocalPlayer
local Character = Player.Character
local TS = game:GetService("TweenService")
local FadeFrame = Player.PlayerGui:WaitForChild("UI_Holder").Fade

RE.OnClientEvent:Connect(function(Key,String,Bool)
	
	if Key == "KeyWord" then -- Text Function
		
		
		if Bool == true then
			Player.PlayerGui.UI_Holder.Notification.Text = String
		else
			local TextAmount = string.len(String)
			for i = 1,TextAmount do
				local NewString = string.sub(String,1,i)
				Player.PlayerGui.UI_Holder.Notification.Text = NewString
				wait(.1)
			end
			wait(3)
			Player.PlayerGui.UI_Holder.Notification.Text = ""
		end

And help would be amazing! thanks!

1 Like

First off, I recommend using

local PlayerCount = #game.Players:GetPlayers()

and replace any other ones accordingly.

Also, you should use the PlayerCount variable in the if statement in the server script.

Besides that, I’m not completely sure why its not working.

Whoops, my bad, but other than that, everything looks straight forward and I have 0 clue whats wrong.

When you say more people join, do you mean more than 5 people (which is your limit for the if statement to work), or if any one person joins?

When I join lets say, the UI tells me 4 more players are needed. However, when I get a friend to join, it remains to say 4 players needed.

I can’t seem to replicate the issue. It seems to work for me.
Have you tried using print statements for the variable PlayerCount before and after the if statement as there could be some type of disconnect there?

I have no idea but changing it to :GetPlayers() seemed to have fixed the issue, thanks guys!

1 Like