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: find the number of players in the server at the current time

Previous Thread :: Next Thread 
dj7679 is not online. dj7679
Joined: 11 Jun 2013
Total Posts: 307
10 Aug 2017 11:37 PM
Does anyone know any other way of finding out how many players are in the server at the current time. The problem I'm having with my script is that even when more than one player is on the server it doesn't run the if statement that its supposed to run. Here's my code:

minigames = game.Lighting.Minigames:GetChildren()

h = Instance.new("Hint", game.Workspace)

while true do

if game.Players.NumPlayers > 1 then
h.Text = "Deciding what game to play"
wait(3)
ranGame = math.random(1, #minigames)
gameChosen = minigames[ranGame]
wait(3)
h.Text = "Minigame Choosen: ".. gameChosen.Name
wait(3)
gameChosenClone = ga################## gameChosenClone.Parent = game.Workspace

--Teleporting people to map
spawns = gameChosenClone.Spawns:GetChildren()
for i,v in pairs(game.Players:GetPlayers())
do
name = v.Name
check = game.Workspace:FindFirstChild(name)
if check then
checkhuman = check:FindFirstChild("Humanoid")
if checkhuman then
check:MoveTo(spawns[i].Position)
end
end
end
for i = 3,1,-1 do
h.Text = "Game Begin in "..i
wait(1)
end
--countdown until game ends
for i = 10,1,-1 do
h.Text = "Time Left: "..i
wait(1)
end
h.Text = "Game ended"
wait(3)
gameChosenClone:Destroy()
else
h.Text = "There needs to be more than 1 player to start"
end
wait(1)
end




Like when I put game.Players.NumPlayers > 1 the hint.Text remains "There needs to be more than 1 player to start" even though there is more than one player in the game but when I do game.Players.NumPlayers == 1 then it works what am I doing work I want to make it so that only when there is more than 1 player in the game the game can start I tried game.Players.NumPlayers > 1 but like I said it still gives me the else result instead of running the if part irdk if you guys understand my question though
Report Abuse
Kizonn is online. Kizonn
Joined: 05 Apr 2017
Total Posts: 841
10 Aug 2017 11:55 PM
you forgot to delete the message


Report Abuse
Mineloxer is not online. Mineloxer
Joined: 18 Dec 2014
Total Posts: 20
11 Aug 2017 12:03 AM
NumOfPlrs = #game.Players:GetChildren()
print("There is " .. tostring(NumOfPlrs) .. " players in the server")

or

NumOfPlrs = 0

for i, plr in pairs (game.Players) do
NumOfPlrs = NumOfPlrs + 1
end
print("There is " .. tostring(NumOfPlrs) .. " players in the server")
Report Abuse
drysty is not online. drysty
Joined: 07 Dec 2013
Total Posts: 1913
11 Aug 2017 12:29 AM
^
Report Abuse
SinisterMemories is not online. SinisterMemories
Joined: 21 Mar 2013
Total Posts: 4892
11 Aug 2017 12:31 AM
game.Players.Changed:Connect(function()
local players = game.Players:GetChildren()

print("there is, "..#players.." players ingame right now")
end)


attempt to index global 'soul' (a nil value)
Report Abuse
SinisterMemories is not online. SinisterMemories
Joined: 21 Mar 2013
Total Posts: 4892
11 Aug 2017 12:33 AM
or yknow shorten it more


game.Players.Changed:Connect(function()
print("there is, "..#game.Players:GetChildren().." players ingame right now")
end)



attempt to index global 'soul' (a nil value)
Report Abuse
dj7679 is not online. dj7679
Joined: 11 Jun 2013
Total Posts: 307
11 Aug 2017 01:32 PM
So many great people who know how to script but why aren't you guys making games with that knowledge xD
Report Abuse
Blastertron221 is not online. Blastertron221
Joined: 31 Mar 2015
Total Posts: 27
11 Aug 2017 01:33 PM
You know, people would be able to actually fix the code if it wasn't for Roblox tagging things on scripts.
Report Abuse
Horrible_Pun is not online. Horrible_Pun
Joined: 13 May 2017
Total Posts: 5102
11 Aug 2017 01:34 PM
i dont suggest putting stuff in lighting
put it in replicatedstorage
Report Abuse
Blastertron221 is not online. Blastertron221
Joined: 31 Mar 2015
Total Posts: 27
11 Aug 2017 01:36 PM
It doesn't make a difference.
Report Abuse
Horrible_Pun is not online. Horrible_Pun
Joined: 13 May 2017
Total Posts: 5102
11 Aug 2017 01:37 PM
putting stuff in lighting can sometimes cause glitches
not always, but sometimes
Report Abuse
dj7679 is not online. dj7679
Joined: 11 Jun 2013
Total Posts: 307
11 Aug 2017 02:55 PM
Bro you are amazing turns out everything was perfect in the script the problem was the fact it was in the lighting just like you said the minute I moved it to replicatedstorage I didn't have to change anything in the script thanks bro appreciate it.
Report Abuse
dj7679 is not online. dj7679
Joined: 11 Jun 2013
Total Posts: 307
11 Aug 2017 02:58 PM
@Horrible_Pun do you know why it makes a difference when you put it in replicatedstorage instead of lighting ? Or is just a roblox thing?
Report Abuse
Lord_Narwhal is not online. Lord_Narwhal
Joined: 05 May 2012
Total Posts: 3242
11 Aug 2017 03:03 PM
@people giving alternate ways to count the number of players

you realize game.Players.NumPlayers is much shorter and does the same thing, right

like you didn't help solve the problem at all


Report Abuse
Horrible_Pun is not online. Horrible_Pun
Joined: 13 May 2017
Total Posts: 5102
11 Aug 2017 03:30 PM
"@Horrible_Pun do you know why it makes a difference when you put it in replicatedstorage instead of lighting ? Or is just a roblox thing?"
i could be wrong but im sure putting stuff in lighting causes script glitches. but it can also definitely be a roblox thing
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