Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does it not go to the next part of the script when there's 2 players?

So I'm making a sword fighting game but it requires 2 people but when there's 2 player in the game it won't do the inmession part here's the script

while true do
	status.Value = "Waiting for at least 2 players in the game"
	
	repeat wait (1) until game.Players.NumPlayers >= 2
	
	for i = 1,25 do
		status.Value = "Wating for the game to start in "..25-i.." seconds"
		wait(1)
	end

There's no error in the output.

2 answers

✓ Accepted answer

the issue is, NumPlayer is not a property of game.Players.. but you can get an array of player's in the server then use table.getn(array) or the pound operator(#) to get the number of player's in the server

like this:

while true do
    status.Value = "Waiting for at least 2 players in the game"

    repeat wait (1) until #game.Players:GetPlayers() > 1

    for i = 1,25 do
        status.Value = "Wating for the game to start in "..25-i.." seconds"
        wait(1)
    end
end

The reason it didn't work was because you haven't defined numplayers. NumPlayers is not a member of game.Players and also you have to get the players that are being referenced.Try this script.

local players = game:GetService(“Players”)

--Check player count, run stuff if it’s high enough
while wait() do
status.Value = "Waiting for at least 2 players in the game"
    if #players:GetPlayers() > 2 then -- Change this number to whatever you want
        print(“Enough players!”)
for i = 1,25 do
        status.Value = "Wating for the game to start in "..25-i.." seconds"
        wait(1)
    
    else
        print(“Not enough”) --Change this line to whatever you want like changing a GUI
    end
end
end

If my answer helped make sure to upvote and accept my answer.

This discussion is preserved as it was. New answers, comments, and votes are closed.