Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do you print specific value in table?

How can you print from the table i want to print 5 from the tables but it won't print.

local Game = {5,10,20}

for i,v in pairs(Game) do
	Game[i] = v+5
	print(v[1])
end

1 comment

0

What are you casually trying to do?

2 answers

There are a bunch of things wrong with your script:

Firstly, avoid using table names similar to services or in this case the actual game object. Secondly you don't have to loop through the table in order to print what you want, you can do it as easily as this

local Table = {5,10,20} --changed the table name so that it doesn't get mixed up with the actual game object

print(Table[1]) --you select the first index inside of the Table array and print it

If this helped you solve your problem please mark it as the answer!

2 comments

0

my answer better

0

XD

There is a difference between a dictionary and an array in tables, a dictionary can have specific values called upon but in an array you must know where that is located. Here is an example of an array:

local Game = {1,2,3}

And here is an example of a dictionary:

local Game ={
["a"] = 1,
["b"] = 2,
["c"] = 3
}

To call upon a specific place in a dictionary, simply use:

game["c"] -- // example

TL;DR: use this:

local Game = {
[1] = 5,
[2] = 10,
[3] = 20
}

for i,v in pairs(Game) do
    print(Game[i])
end

This discussion is preserved as it was. New answers, comments, and votes are closed.