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: Tables are not working

Previous Thread :: Next Thread 
Gomlsauresrex is not online. Gomlsauresrex
Joined: 25 Mar 2016
Total Posts: 3588
09 Feb 2017 04:20 PM
local contestants = {}

game.Players.ChildAdded:connect(function(player)
table.insert(contestants, player)
end)

game.Players.ChildRemoved:connect(function(player)
table.remove(contestants, player)
end

while true do
print(#contestants)
wait(10)
end
Report Abuse
Gomlsauresrex is not online. Gomlsauresrex
Joined: 25 Mar 2016
Total Posts: 3588
09 Feb 2017 04:20 PM
Halp
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
09 Feb 2017 04:21 PM
what's the point of this anyway? game:GetService("Players"):GetPlayers() returns a table of all players currently in the server


Report Abuse
Lua_Basics is not online. Lua_Basics
Joined: 04 Jun 2012
Total Posts: 9977
09 Feb 2017 04:21 PM
game.Players.NumPlayers
Report Abuse
Gomlsauresrex is not online. Gomlsauresrex
Joined: 25 Mar 2016
Total Posts: 3588
09 Feb 2017 04:23 PM
just testing this.

lel.
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
09 Feb 2017 05:10 PM
local playing = {}

game.Players.PlayerAdded:connect(function(player)
playing[player] = true
end)

game.Players.PlayerRemoving:connect(function(player)
playing[player] = nil
end)

while wait() do
for k,v in next, playing do
print(k)
end
end


Report Abuse
Yvnx is not online. Yvnx
Joined: 21 May 2016
Total Posts: 73
09 Feb 2017 05:18 PM
flip the table lol
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
09 Feb 2017 07:01 PM
that is not how a remove works, remove will get rid of the value at that index in an array, not the key with that value
Report Abuse
Mister_Manakin is not online. Mister_Manakin
Joined: 16 Sep 2009
Total Posts: 1935
09 Feb 2017 07:05 PM
If the player objects are stored in the array, wouldn't the values just change to nil when the player leaves?
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
09 Feb 2017 07:06 PM
it's just a horrible method of doing it to begin with


Report Abuse
reptoslicerguy is not online. reptoslicerguy
Joined: 01 Jan 2010
Total Posts: 2098
09 Feb 2017 07:14 PM
local players = ## function ################### print(player, " was added") table.insert(players, player) end function playerRemoved(player) print(player, " was removed") for ## i in ipairs(players) do if player ## players[i] then table.remove(players, i) end end end while wait(10) do print(#players) end
Report Abuse
reptoslicerguy is not online. reptoslicerguy
Joined: 01 Jan 2010
Total Posts: 2098
09 Feb 2017 07:15 PM
local players = {}

function playerAdded(player)
print(player, " was added")
table.insert(players, player)
end
function playerRemoved(player)
print(player, " was removed")
for _, i in ipairs(players) do
if player == players[i] then
table.remove(players, i)
end
end
end


game.Players.PlayerAdded:connect(playerAdded)
game.Players.PlayerRemoving:connect(playerRemoved)

Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
09 Feb 2017 07:16 PM
if you want to be slightly more efficient

local contestants = {}
local count = 0

game.Players.PlayerAdded:connect(function(player)
contestants[ player ] = player
count = count + 1
end)

game.Players.PlayerRemoving:connect(function(player)
contestants[ player ] = nil
count = count - 1
end
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
09 Feb 2017 07:33 PM
if you want to be slightly more efficient local contestants = ####################################### local count = #contestants
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
09 Feb 2017 07:33 PM
if you want to be slightly more efficient

local contestants = game.Players:GetPlayers()
local count = #contestants


Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
09 Feb 2017 07:36 PM
ik but other than that cuz you could just do local ## # ################ "Players" ) local gc = pl.GetChildren while wait(10) do print( #gc(pl) ) end
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