--Variables-- local plr = game:GetService('Players') local sg = game:GetService('StarterGui') --Functions-- function message(text,color) sg:SetCore("ChatMakeSystemMessage", { Text = text or error("Text is nil"), Color = color or Color3.fromRGB(225,225,225), Font = Enum.Font.SourceSans, FontSize = Enum.FontSize.Size24, }) end function lookForPlayers() while true do wait() local playerCount = script.Parent:WaitForChild("playerCounter").existingPlayers.Value if playerCount >= 2 then print("There is enough players!") break else print("Not enough players!") end end end --Main-- lookForPlayers() wait() message("The round is about to start!", Color3.fromRGB(0,225,0)) -- Wont write the message in the server chat
Have you tried print debugging? Perhaps playerCount
isn't updating properly. Somehow the loop is becoming endless.
Reguardless, you can use the GetPlayers
function of Players to return a table that consists of all the current players in game. Use the #
operator on this table to return the number of entries; i.e, the number of players.
And here is a cleaner way to go about waiting with the while
loop:
function lookForPlayers() local plrs = #game.Players:GetPlayers() --Initially recieve player amount --Establish loop and conditions for iteration while plrs < 2 and wait() do print("Not enough players"); plrs = #game.Players:GetPlayers() --Update val end print("There is enough players!"); end