generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Script not working? Small script

Previous Thread :: Next Thread 
AdvancedDrone is online. AdvancedDrone
Joined: 17 Apr 2010
Total Posts: 2599
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 is not online. 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 is not online. 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 is not online. 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
LuaDeveloped is not online. LuaDeveloped
Joined: 28 Jan 2016
Total Posts: 439
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
BloodDragonII is not online. BloodDragonII
Joined: 05 May 2012
Total Posts: 1187
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 is online. 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 is not online. 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 is not online. 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 is not online. 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 is online. imaski4
Joined: 29 Nov 2015
Total Posts: 7
02 Dec 2017 01:48 PM
TNTeon you have to use == false ok
Report Abuse
TNTeon is not online. 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
BloodDragonII is not online. BloodDragonII
Joined: 05 May 2012
Total Posts: 1187
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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image