Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you check if there is four players?

Asked by 9 years ago

I have made this:

if game.Players.NumPlayers >= 4 then

end
0
No errors or anything in output... antlerer 33 — 9y
0
and... your point.... it works, it's cause you need it to DO something inside the if statement NinjoOnline 1146 — 9y

2 answers

Log in to vote
0
Answered by 9 years ago
if game.Players.NumPlayers >= 4 then -- Check for 4 or more players
    print("There is four or more players in the game") -- Print in output
    -- Extra Code
end

This should work, you never had it to check. You should also add a while true do loop to constantly check if there is 4 players..

while wait() do -- Loop through to constantly do what is inside code
    if game.Players.NumPlayers >= 4 then -- Check for 4 or more players
        print("There is four or more players in the game") -- Print in output
        -- Extra Code
    end
end

If this helped then remember to rate up and accept answer for others.

0
Okay :D I will try it and I will rate you up :D antlerer 33 — 9y
0
Wait it says: 12:04:40.422 - Player is not a valid member of DataModel 12:04:40.422 - Script 'Workspace.Script', Line 2 12:04:40.423 - Stack End antlerer 33 — 9y
0
On line 2, he put "game.Player" which is wrong, it suppose to be "game.Players" Coolviper630 95 — 9y
0
Mine should work now NinjoOnline 1146 — 9y
Ad
Log in to vote
0
Answered by
Discern 1007 Moderation Voter
9 years ago

Your error is that the script is running before there are 4 players in the game, and the script just stops there. You need the script to run over and over to continually check if there are 4 players.

I prefer not to use while loops. I think repeat loops would be better for this. Repeat loops run until the statement after "Until" is true. Then the code continues once the conditional statement is met.

repeat wait() until game.Players.NumPlayers >= 4
print("There is four or more players in the game!")
0
That doesn't seem to print it. antlerer 33 — 9y
0
I just tested it, and it printed just fine for me when I inserted 4 players into a game. Discern 1007 — 9y

Answer this question