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: Question

Previous Thread :: Next Thread 
ShadowAley is not online. ShadowAley
Joined: 23 Jun 2010
Total Posts: 4823
01 Jun 2015 04:26 PM
I'm having trouble with tables. How do you check if something is in a table?


game.Players.PlayerAdded:connect(function(plr)
local plrz = plr.Name
plr.CharacterAdded:connect(function(char)
char.Humanoid.Died:connect(function()
if activeplayers.plrz then
table.remove(activeplayers, plr.Name)
else
print("no game")
end
end)
end)
end)



My players name is in the table (I used print), but it keeps printing "no game"
Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
01 Jun 2015 04:28 PM
Since you're adding it as a value, you can't just check if it's there.

Rather than telling you to loop through the table, use a simpler solution.

local activeplayers = {}

game.Players.PlayerAdded:connect(function(plr)
local plrz = plr.Name
plr.CharacterAdded:connect(function(char)
char.Humanoid.Died:connect(function()
if activeplayers[plrz] then
activeplayers[plrz] = nil
else
print("no game")
end
end)
end)
end)

Don't do

table.insert(activeplayerz, plrz)

Do

activeplayers[plrz] = true

Report Abuse
ShadowAley is not online. ShadowAley
Joined: 23 Jun 2010
Total Posts: 4823
01 Jun 2015 04:32 PM
That didn't work :/
Report Abuse
ShadowAley is not online. ShadowAley
Joined: 23 Jun 2010
Total Posts: 4823
01 Jun 2015 04:34 PM
How I insert:

for i,v in pairs(game.Players:GetPlayers()) do
activeplayers[v] = true
print("inserted "..v.Name.." into activeplayers table")
v.Character.Torso.CFrame = spawns[math.random(#spawns)].CFrame
v.Character.Humanoid.WalkSpeed = 0
end



game.Players.PlayerAdded:connect(function(plr)
local plrz = plr.Name
plr.CharacterAdded:connect(function(char)
char.Humanoid.Died:connect(function()
if activeplayers.plrz then
table.remove(activeplayers, plr.Name)
end
end)
end)
end)




This isn't removing ^
Report Abuse
ShadowAley is not online. ShadowAley
Joined: 23 Jun 2010
Total Posts: 4823
01 Jun 2015 04:39 PM
b
Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
01 Jun 2015 04:40 PM
You need to make sure you read things before trying them. I showed you to _not_ use table.remove. Do

activeplayers[plrz] = nil

Instead
Report Abuse
ShadowAley is not online. ShadowAley
Joined: 23 Jun 2010
Total Posts: 4823
01 Jun 2015 04:47 PM
Okay so when I use

game.Players.PlayerAdded:connect(function(plr)
local plrz = plr.Name
plr.CharacterAdded:connect(function(char)
char.Humanoid.Died:connect(function()
if activeplayers[plrz] then
activeplayers[plrz] = nil
else
print("no game")
end
end)
end)
end)



This, automatically breaks the end?

for i = 45, 0, -1 do
wait(1)
print(table.concat(activeplayers, ' '))
status.Value = i
if #activeplayers == 0 then break end
end
Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
01 Jun 2015 04:50 PM
You can't count non-numerical indices. The table is always 0.
Report Abuse
ShadowAley is not online. ShadowAley
Joined: 23 Jun 2010
Total Posts: 4823
01 Jun 2015 04:51 PM
How would I check if the table is empty then? I rarely use them
Report Abuse
ShadowAley is not online. ShadowAley
Joined: 23 Jun 2010
Total Posts: 4823
01 Jun 2015 05:59 PM
b
Report Abuse
ShadowAley is not online. ShadowAley
Joined: 23 Jun 2010
Total Posts: 4823
01 Jun 2015 10:39 PM
b
Report Abuse
ShadowAley is not online. ShadowAley
Joined: 23 Jun 2010
Total Posts: 4823
01 Jun 2015 11:05 PM
b2
Report Abuse
ShadowAley is not online. ShadowAley
Joined: 23 Jun 2010
Total Posts: 4823
01 Jun 2015 11:29 PM
b3
Report Abuse
ShadowAley is not online. ShadowAley
Joined: 23 Jun 2010
Total Posts: 4823
01 Jun 2015 11:36 PM
b4
Report Abuse
ShadowAley is not online. ShadowAley
Joined: 23 Jun 2010
Total Posts: 4823
02 Jun 2015 12:26 AM
b5
Report Abuse
ShadowAley is not online. ShadowAley
Joined: 23 Jun 2010
Total Posts: 4823
02 Jun 2015 12:38 AM
bb
Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
02 Jun 2015 08:02 AM
function CountTable(Table)
local X = 0
for i,v in pairs(Table) do
X = X + 1;
end
return X
end
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
02 Jun 2015 09:38 AM
local table = require(199207348)

if table.find(activeplayers, plrz) then
--code
end
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
02 Jun 2015 09:40 AM
local table = require(199207348)

if table.length(tab) > 0 then
--not empty
end
Report Abuse
ShadowAley is not online. ShadowAley
Joined: 23 Jun 2010
Total Posts: 4823
02 Jun 2015 08:21 PM
for i = 45, 0, -1 do
wait(1)
print(table.concat(activeplayers, ' '))
status.Value = i
CountTable()
if X == 0 then break end
end


Okay so how do I see what CountTable returns?
Report Abuse
ShadowAley is not online. ShadowAley
Joined: 23 Jun 2010
Total Posts: 4823
02 Jun 2015 08:26 PM
Also, I'm receiving this error,

20:24:46.812 - ServerScriptService.Mainscript:17: bad argument #1 to 'pairs' (table expected, got nil)
Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
02 Jun 2015 09:06 PM
"CountTable()
if X == 0 then break end"

To

if CountTable(activeplayers) == 0 then break end
Report Abuse
ShadowAley is not online. ShadowAley
Joined: 23 Jun 2010
Total Posts: 4823
02 Jun 2015 09:08 PM
Awesome thanks.

So this isn't working though:

game.Players.PlayerAdded:connect(function(plr)
local plrz = plr.Name
plr.CharacterAdded:connect(function(char)
char.Humanoid.Died:connect(function()
if activeplayers[plrz] then
activeplayers[plrz] = nil
else
print("no game")
end
end)
end)
end)




The player is indeed, in the table, as through the print I used in the loop
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
03 Jun 2015 04:05 AM
local table = require(199207348)

game.Players.PlayerAdded:connect(function(plr)
local plrz = plr.Name
plr.CharacterAdded:connect(function(char)
char.Humanoid.Died:connect(function()
local found, value, index = table.find(activeplayers, plrz)
if found then
activeplayers[index] = nil
else
print("no game")
end
end)
end)
end)
Report Abuse
murcury57 is not online. murcury57
Joined: 30 Jun 2010
Total Posts: 90299
03 Jun 2015 04:56 AM
[ Content Deleted ]
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