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: Getting a value straight from a table

Previous Thread :: Next Thread 
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
05 Jun 2015 01:48 PM
I'm having a bit of a problem, don't know why it's doing this.

-- game inserts Player names into this table
local Players = {Player1}
for i,Player in pairs (game.Players:GetPlayers()) do
if Players[Player.Name] then -- Does not go past this point

end
end

I printed both the table and Player.Name, they both print Player1. Why doesn't it go past the if statement?
Report Abuse
amanda is not online. amanda
Joined: 21 Nov 2006
Total Posts: 5925
05 Jun 2015 01:50 PM
Table[index]

not

Table[value]
Report Abuse
Qivr is not online. Qivr
Joined: 22 Aug 2014
Total Posts: 5407
05 Jun 2015 01:50 PM
local Players = {Player1}

>>>

local Players = {"Player1"}
Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
05 Jun 2015 01:52 PM
Because that key doesn't exists. You are storing the player names as values, apparently. You need to store them as keys to do that:

local Players = {['Player1'] = true};

if Players['Player1'] then
-- works
end

Or make a function to search the table for the value.

function Search(Table, Value)
for i,v in pairs(Table) do
if v == Value then
return true
end
end
end

if Search(Players, Player.Name) then
Report Abuse
amanda is not online. amanda
Joined: 21 Nov 2006
Total Posts: 5925
05 Jun 2015 01:53 PM
^
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
05 Jun 2015 01:53 PM
local Players = {"Player1","Player"}
wait(2)
for i,v in pairs (Players) do
for i,x in pairs(game.Players:GetChildren()) do
if x.Name == v then
print("hello player")
end
end
end
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
05 Jun 2015 05:32 PM
Is there a way to save the players as strings?

for i,v in pairs (Game.Players:GetChildren()) do
table.insert(Players, Player.Name) --stringify!
end
Report Abuse
amanda is not online. amanda
Joined: 21 Nov 2006
Total Posts: 5925
05 Jun 2015 05:33 PM
yes
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
05 Jun 2015 06:19 PM
I already had it like that with Player.Name, so it should be string

Forgot to mention that
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
05 Jun 2015 07:12 PM
So the real table is probably

local Players = {"Player1"}
if Players[Player.Name] then

They should be the exact same
Report Abuse
CrescentJade is not online. CrescentJade
Joined: 07 Jul 2010
Total Posts: 5494
05 Jun 2015 07:15 PM
as an appropriate answer to the title,

rawget(tab,i)
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
06 Jun 2015 07:34 AM
I was just trying to do

Table["String"] because that works too
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
06 Jun 2015 07:43 AM
-- Sets all players to table
table.insert(Players, Player.Name)

-- Sees if player is in table
if Players[Player.Name] then


Both should be string values.
Report Abuse
epicbreaker is not online. epicbreaker
Joined: 23 Apr 2011
Total Posts: 2791
06 Jun 2015 07:46 AM
Well then, instead of: table.insert(Players, Player.Name)
Do this:
Players[Player.Name] = true
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
06 Jun 2015 07:47 AM
Figured out doing this works:

for i,v in pairs (Players) do
if v == Player.Name then

But why doesn't players[PLayer.Name] work? It's way easier to use
Report Abuse
epicbreaker is not online. epicbreaker
Joined: 23 Apr 2011
Total Posts: 2791
06 Jun 2015 07:48 AM
Maybe you should understand tables first.

http://wiki.roblox.com/index.php?title=Table
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
06 Jun 2015 08:00 AM
local table = require(199207348)

local Players = {"Player1"}
for i, Player in pairs(game.Players:GetPlayers()) do
if table.find(Players, Player.Name) then

end
end
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
06 Jun 2015 08:43 AM
How would you remove dictionary indexes?
table ={["Player1"] = true}

for i,v in pairs (Players) do
if i == Player.Name then
table.remove(Players, v) -- Doesn't work, can't use i or v?
end
end
Report Abuse
WishNite is not online. WishNite
Joined: 11 Feb 2009
Total Posts: 15828
06 Jun 2015 08:46 AM
table[Player1] = nil
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
06 Jun 2015 09:43 AM
Are you able to do #Players with dictionaries
Report Abuse
epicbreaker is not online. epicbreaker
Joined: 23 Apr 2011
Total Posts: 2791
06 Jun 2015 10:40 AM
No.
Report Abuse
ParticleAffects is not online. ParticleAffects
Joined: 15 Feb 2012
Total Posts: 632
06 Jun 2015 10:41 AM
No
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
06 Jun 2015 10:45 AM
local table = require(199207348)

print(table.length(dictionary))
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