How do I get a value from a table

I have a script here that stores clothes that go with specific ranks, how do I get the shirt/pants value?

		["Master"] = {Shirt="rbxassetid://579465683",Pants="rbxassetid://579465640"},

Ive tried role.Pants but it came up with Nil

Assuming your table is called role, here’s how you would access it:

local role = {
    ["Master"] = {Shirt="rbxassetid://579465683",Pants="rbxassetid://579465640"},
}

print(role["Master"].Shirt) -- returns "rbxassetid://579465683"

If role is the string, "Master", then all you would do is use that string when indexing the table:

local tbl = {
    ["Master"] = {Shirt="rbxassetid://579465683",Pants="rbxassetid://579465640"},
}
local role = "Master"

print(tbl[role].Shirt) -- returns "rbxassetid://579465683"
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.