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: How to check how many Values == true?

Previous Thread :: Next Thread 
excellentAnarchy is not online. excellentAnarchy
Joined: 30 Dec 2008
Total Posts: 2557
22 Jan 2017 12:29 PM
So I have a value inside of every player in my game,
My question is how to I keep track of how many of those values == true?

My take on this is:

while true do wait(1)
local players = game.Players:GetChildren()
for i, player in ipairs(game.Players:GetChildren()) do
if player.Playing == true then
-- keep track of how many of players have the value set to true?
end
end
Report Abuse
TextSoaked is not online. TextSoaked
Joined: 04 Sep 2015
Total Posts: 1040
22 Jan 2017 12:29 PM
use a counter value


Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
22 Jan 2017 12:30 PM
local playing = {}

for _, player in next, game:GetService("Players"):GetPlayers() do
if player.Playing.Value then
table.insert(playing, player)
end
end


Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
22 Jan 2017 12:30 PM
oh you want to count
instead of using a table just increment the integer by 1 each time


Report Abuse
excellentAnarchy is not online. excellentAnarchy
Joined: 30 Dec 2008
Total Posts: 2557
22 Jan 2017 12:31 PM
I have absolutely no clue how to keep track of this, because players will also join/leave the game, affecting the amount of those values enabled.
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
22 Jan 2017 12:31 PM
connect the counter increment/decrement to PlayerAdded and PlayerRemoving events


Report Abuse
excellentAnarchy is not online. excellentAnarchy
Joined: 30 Dec 2008
Total Posts: 2557
22 Jan 2017 12:55 PM
I don't want this to keep track of the number of players, I want this to keep track of how many players have the value set to true
Report Abuse
excellentAnarchy is not online. excellentAnarchy
Joined: 30 Dec 2008
Total Posts: 2557
22 Jan 2017 01:09 PM
b
Report Abuse
excellentAnarchy is not online. excellentAnarchy
Joined: 30 Dec 2008
Total Posts: 2557
22 Jan 2017 01:18 PM
b
Report Abuse
Bos5SlayeR is not online. Bos5SlayeR
Joined: 06 Mar 2014
Total Posts: 340
22 Jan 2017 01:34 PM
Loop it and it will check the players every dam second if someone leaves it wont count them. like create local count = 0 and if player.Playing.Value == true count should be count = count + 1. ez pz
Report Abuse
excellentAnarchy is not online. excellentAnarchy
Joined: 30 Dec 2008
Total Posts: 2557
22 Jan 2017 01:46 PM
I still seem to be lost after giving it a few tries
Report Abuse
Bos5SlayeR is not online. Bos5SlayeR
Joined: 06 Mar 2014
Total Posts: 340
22 Jan 2017 01:57 PM
Hmm.Try making a global Value. And if player.Playing.Changed:connect and if its true Value = Value + 1 . if false Value = Value - 1 . if PlayerLeft Check all other players values.
Report Abuse
Nartronic is not online. Nartronic
Joined: 28 Aug 2014
Total Posts: 916
22 Jan 2017 02:27 PM
function GetPlayerCount()
local Count = 0
local Players = game.Players:GetChildren()
for _, Player in ipairs(Players) do
if player.Playing == true then
Count = Count + 1
end
end
return Count
end

local PlayersReady = GetPlayerCount()


Report Abuse
excellentAnarchy is not online. excellentAnarchy
Joined: 30 Dec 2008
Total Posts: 2557
22 Jan 2017 02:49 PM
That wouldn't work as I explained.

I want this to keep track of how many players have the value set to true, and this might change due to players joining/leaving the game or even by dieing. So I would like the counting to be done in real-time, and constantly updated.
Report Abuse
Wowgnomes is online. Wowgnomes
Joined: 27 Sep 2009
Total Posts: 26255
22 Jan 2017 03:07 PM
When a value changes to true, have it change the count of a numb val in server storage, if you don't want to cycle thru all the players.


Report Abuse
excellentAnarchy is not online. excellentAnarchy
Joined: 30 Dec 2008
Total Posts: 2557
22 Jan 2017 05:45 PM
@Wowgnomes,
But, what about when a player leaves the game? There won't be a change in value, but a change in Player count - which will still affect the value.
Report Abuse
electricpretzel0 is not online. electricpretzel0
Joined: 30 Sep 2008
Total Posts: 1278
22 Jan 2017 05:55 PM
um?



function CountPlayersWithBoolean()
local bools = 0

for i, v in pairs(game.Players:GetChildren()) do
if v:findFirstChild("YourVariable") then
if v.YourVariable.Value == true then
bools = bools + 1
end
end

return bools

end
Report Abuse
excellentAnarchy is not online. excellentAnarchy
Joined: 30 Dec 2008
Total Posts: 2557
22 Jan 2017 06:01 PM
Again, that script will not check if players have left the game, and will not have an effect on the counter. And running that in a loop would constantly be adding 1 to my counter.
Report Abuse
Gomlsauresrex is not online. Gomlsauresrex
Joined: 25 Mar 2016
Total Posts: 3588
22 Jan 2017 06:08 PM
local number = 0
for i, person in ipairs(game.Players:GetPlayers()) do
if person.Playing then
number = number + 1
else
number = number - 1
end
game.Players.ChildRemoved:connect(function()
if person.Playing == false then
number = number
else
number = number - 1
end
end)
end
Report Abuse
excellentAnarchy is not online. excellentAnarchy
Joined: 30 Dec 2008
Total Posts: 2557
22 Jan 2017 06:14 PM
Well this only changes the number if the Player has the Value enabled whilst joining the game. I want the counter to be real-time, checked every second or so,

local number = game.ServerScriptService.InGame.Value

for i, person in ipairs(game.Players:GetPlayers()) do
if person.Playing then
number = number + 1
else
number = number - 1
end
game.Players.ChildRemoved:connect(function()
if person.Playing == false then
number = number
else
number = number - 1
end
end)
end

Report Abuse
excellentAnarchy is not online. excellentAnarchy
Joined: 30 Dec 2008
Total Posts: 2557
22 Jan 2017 06:32 PM
Simple solution:

while true do
game.ServerScriptService.InGame.Value = 0
for _, v in pairs(game.Players:GetPlayers()) do
if v:FindFirstChild("Playing") and v:FindFirstChild("Playing").Value == true then
game.ServerScriptService.InGame.Value = game.ServerScriptService.InGame.Value + 1
end
end
wait()
end
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
22 Jan 2017 06:45 PM
that's such a terrible way to do it
why didn't you incorporate the events like I explained to you?


Report Abuse
Wowgnomes is online. Wowgnomes
Joined: 27 Sep 2009
Total Posts: 26255
22 Jan 2017 07:25 PM
1. do the method i said, put a stringvalue of player's name as child of intvalue total
2. on player leaving, check if their name is in intvalue, if it is, remove it and subtract 1 from intvalue


Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
22 Jan 2017 07:31 PM
using objects for this really isn't necessary


Report Abuse
Nartronic is not online. Nartronic
Joined: 28 Aug 2014
Total Posts: 916
22 Jan 2017 07:32 PM
^


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