|
| 02 Dec 2017 12:26 PM |
So I'm creating a game, and I've never used NumPlayers before and I'm having it so if theres two or more players it would do something, but if theres under two players then it wouldn't do anything until two players.. but it's not working
But how would I make it so it repeats it so it doesn't only work once, because when I test it in studio and I add one player, it prints "not enough players" but when I add another player it doesn't print "starting game"
if game.Players.NumPlayers == 2 then print('starting game') else print('not enough players') end
|
|
|
| Report Abuse |
|
|
LuaCymru
|
  |
| Joined: 22 Jan 2015 |
| Total Posts: 394 |
|
|
| 02 Dec 2017 12:27 PM |
if #game.Players:GetChildren() >= 2 then print('starting game') else print('not enough players') end |
|
|
| Report Abuse |
|
|
LuaCymru
|
  |
| Joined: 22 Jan 2015 |
| Total Posts: 394 |
|
|
| 02 Dec 2017 12:28 PM |
| To make it repeat, just enable and disable the script? depends on how the game works |
|
|
| Report Abuse |
|
|
Aliics
|
  |
| Joined: 29 Sep 2014 |
| Total Posts: 471 |
|
|
| 02 Dec 2017 01:10 PM |
game.Players.PlayerAdded:connect(function(player)) -- Check for if there enough players end)
-- You might also want to check for the amount of players on PlayerRemoving / PlayerRemoved |
|
|
| Report Abuse |
|
|
|
| 02 Dec 2017 01:23 PM |
| Use the playeradded function and you also have a error use >=2 rather than ==, otherwise it will only run if there is 2 players no more or no less. |
|
|
| Report Abuse |
|
|
|
| 02 Dec 2017 01:24 PM |
number = 0
function count() for i,v in pairs(game.Players:GetPlayers()) do number = i print(number.. " Online") end if number >= 2 then print("There are enough players") elseif number < 2 then print("Not Enough Players!") end end
game.Players.PlayerAdded:Connect(count) game.Players.PlayerRemoving:Connect(count)
This script will count the number of players everytime someone joins or leaves and after it finishes counting if there are 2 or more players it will print that theres enough players if not it will say not enough players replace whats inide the if statements with what you want it to do |
|
|
| Report Abuse |
|
|
Savi_ooo
|
  |
| Joined: 10 Jun 2012 |
| Total Posts: 214 |
|
|
| 02 Dec 2017 01:26 PM |
local Players = game:GetService('Players')
local function Check() if #Players:GetPlayers() >= 2 then return true end return false end
while wait() do if Check() then print('Starting Game') else warn('Insufficient Players') end end
~ 𝓢𝖆𝖛𝖎 |
|
|
| Report Abuse |
|
|
TNTeon
|
  |
| Joined: 31 Jul 2017 |
| Total Posts: 5 |
|
|
| 02 Dec 2017 01:42 PM |
can someone help me, I am getting this error that says
ServerScriptService.MainScript:69: 'do' expected near '='
this is my code
for i = 60,0,-1 and KingTouch = false do
I know it has a problem with my = sign but i don't know why, please help me! |
|
|
| Report Abuse |
|
|
TNTeon
|
  |
| Joined: 31 Jul 2017 |
| Total Posts: 5 |
|
|
| 02 Dec 2017 01:46 PM |
by the way the answer to your problem is
while game.Players.NumPlayers < 2 do print('There needs to be 4 or more players to begin') repeat wait(2) until game.Players.NumPlayers >= 2 end
print('starting game') |
|
|
| Report Abuse |
|
|
TNTeon
|
  |
| Joined: 31 Jul 2017 |
| Total Posts: 5 |
|
|
| 02 Dec 2017 01:47 PM |
sorry it should be
while game.Players.NumPlayers < 2 do print('There needs to be 2 or more players to begin') repeat wait(2) until game.Players.NumPlayers >= 2 end
print('starting game') |
|
|
| Report Abuse |
|
|
imaski4
|
  |
| Joined: 29 Nov 2015 |
| Total Posts: 7 |
|
|
| 02 Dec 2017 01:48 PM |
| TNTeon you have to use == false ok |
|
|
| Report Abuse |
|
|
TNTeon
|
  |
| Joined: 31 Jul 2017 |
| Total Posts: 5 |
|
|
| 02 Dec 2017 01:51 PM |
now it says
ServerScriptService.MainScript:69: 'for' step must be a number |
|
|
| Report Abuse |
|
|
|
| 02 Dec 2017 01:52 PM |
| TNTeon the KingTouch = false should be in an if statement and include the for statement in it |
|
|
| Report Abuse |
|
|
TNTeon
|
  |
| Joined: 31 Jul 2017 |
| Total Posts: 5 |
|
|
| 02 Dec 2017 01:58 PM |
| I want it to stop changing i too and move on to the following script |
|
|
| Report Abuse |
|
|