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
|
  |
| Joined: 05 Apr 2017 |
| Total Posts: 841 |
|
|
| 10 Aug 2017 11:55 PM |
you forgot to delete the message
|
|
|
| Report Abuse |
|
|
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
|
  |
| Joined: 07 Dec 2013 |
| Total Posts: 1913 |
|
| |
|
|
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 11 Aug 2017 01:34 PM |
i dont suggest putting stuff in lighting put it in replicatedstorage |
|
|
| Report Abuse |
|
|
|
| 11 Aug 2017 01:36 PM |
| It doesn't make a difference. |
|
|
| Report Abuse |
|
|
|
| 11 Aug 2017 01:37 PM |
putting stuff in lighting can sometimes cause glitches not always, but sometimes |
|
|
| Report Abuse |
|
|
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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|