I have tried this:
if game.Players.NumPlayers >= 4 then
-- I put my code here...
end
I have tried this:
if game.Players.NumPlayers >= 4 then
-- I put my code here...
end
You could put your main script into a function. You could do that like this:
function Round()
--Code
end
And I assume you would like for there to be 4 players or higher. So, to do that, you could loop your function and check if there were 4 or more players.
while true do
if game.Players.NumPlayers >= 4 then
Round()
else
break --Exits the loop and nothing happens
end
wait(1) --Always end your infinite loops (while true do) with a wait. Otherwise, studio will crash and you have to start over.
end
Note: Once you add repeat wait() until game:GetService('Players').NumPlayers >= 4, it pauses the rest of the script until there is 4 or more players.
Run code once if there is 4 or more players:
repeat wait() until game:GetService('Players').NumPlayers >= 4
-- your code here
Run once every time a player joins if there is 4 or more players:
game:GetService('Players').PlayerJoined:connect(function(player)
if game:GetService('Players').NumPlayers >= 4 then
-- your code here
end
end)
Run code every 0.03 seconds if there is 4 or more players:
while true do
if game:GetService('Players').NumPlayers >= 4 then
-- your code here
end
wait()
end
This discussion is preserved as it was. New answers, comments, and votes are closed.
5 comments
So I put my code under Round?()
Yes. And the part below calls the function.
It says "Player is not a valid member or Datamodel"
..?
Oh I haven't said what Round() is yet XD.