Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is this outputting the table's location?

Asked by 8 years ago

My code is linked to a website outputting a json file (URL not proved for security), the json file and the code is below

Json file ``[{"Room":"Room","Name":"Name"},{"Room":"Room1","Name":"Name1"}]

Lua code (on a button)

hs = game:GetService("HttpService") 
local url = (removed, but working URL is here)

script.Parent.MouseButton1Click:connect(function()

local var1 = script.Parent.Parent.Text -- A text box for an input

local users = hs:GetAsync(url.."json2.php")
print(users)
users = hs:JSONDecode(users)
print(users[1])
for i,v in pairs(users) do
    if v == var1 then
        script.Parent.Parent.Parent.TextLabel.Text = "True" -- this is a text label displaying if values are the same
    end
end
end)

The output(s)

[{"Room":"Room","Name":"Name"},{"Room":"Room1","Name":"Name1"}]
table: 1B66DBA8

what I want: if the value of var1 is the same as any value on this table print the name AND the type of room they have (in this case)

1 answer

Log in to vote
0
Answered by
MrNicNac 855 Moderation Voter
8 years ago

Because you have received a table of tables. When you decode the JSON string, you get one table with two more in it. Try this instead:

print(users[1]['Room'])

And to properly index them:

local Table1 = users[1]
local Table2 = users[2]
Ad

Answer this question