Getting a certain table value problem

Alright so straight to the point, I’m working on membership system using module scripts (tables)

image

First table is the membership type, and second one is the membership duration

So when I go to my different serverscript, I try to make a value for the player and put the duration as it’s value, here’s my code, I don’t know what’s wrong with it, I did some research on the internet/devhub and I couldn’t come out with a solution:

image

1 Like

platinum is the value let me explain
the table is looking like this

[1588610618] -- index {} -- and this is a table, and the table does not have a name

if i understood the thing correctly you should do

if v[1] == "Platinum" then

v[1] will be “Platinum”

if it helped please mark it as a solution

2 Likes

Yeah but platinum here is not the problem, naming the value is the problem

1 Like

the value is created? or no? is it just the value?

2 Likes

The value creates it perfectly fine, but I’m trying to put the platinum.Value value as it’s expire date, which is “never” in the table

That’s why i tried v[2]

1 Like

try maybe printing v or v[2] and see whats the problem

2 Likes

It just prints nil but how would i get it the other way?

1 Like
for k, x in pairs(yourindex) do
print(k, x) 
end
1 Like

Now it prints “1, platinum” but when i try v[2] it prints nil, ???

1 Like

Because it works only for arrays.

2 Likes

So how would i get the value, ??

1 Like

Ohhh coz v is the table and it will be “Platinum”, you don’t need a loop for that you can do

local PlayerTable = table[player.UserId]

if PlayerTable[1] == "Platinum" then
    etc...
    value = PlayerTable[2]
2 Likes

You need to use the for loop again. Or make it like this:

[1111] = {Time = 10, Name = "Awesome"}

for i, v in pairs(yourtable) do
print(v["Name"]) 
end
2 Likes

Yeah but I’m gonna automate it later on, so it names the name of the value the first value of the table, so it does need a loop

1 Like

so you can do

local table = {
    [player.UserId] = {"Platinum" = {Expiration = "Never"}}
}

and it will work fine

2 Likes

You mean just add a variable to each table, the code you just wrote confused me, would it work like this?

image

1 Like

Yes this is probably best way to do it.

2 Likes

But wait, what’s the difference, it confuses me mad hard now.

image

1 Like

then you wont need a loop… you will just do
table[player.UserId].Type or Expiration

2 Likes

I’m so confused, whenever somebody buys a membership you are going to manually add them to a table? that doesn’t make sense.

2 Likes