Hello, I have been trying to get the value of an index from a dictionary but I have some problems with it:
-- variables
local player = game.Players.LocalPlayer;
local character = player.Character or player.CharacterAdded:Wait();
local shop = script.Parent;
local container = shop.ScrollingFrame;
local temp = container.Temp;
-- services
local rs = game:GetService('RunService');
local rep = game:GetService('ReplicatedStorage')
-- tables
local backpacks = {};
local array = {};
-- code
for i, v in pairs(rep.Backpacks:GetChildren()) do
backpacks[v.Name] = v:GetAttribute("Order")
end
for key, _ in pairs(backpacks) do
table.insert(array, key)
end
table.sort(array);
for i, key in ipairs(array) do
local backpack = backpacks[key];
print(backpack); -- prints 1,2,3 witch are the orders of the backpacks
end;
But I am trying to print the name of the backpack not the index.
How do I do that?
Thank you!
The “key” variable is already the name of the backpack. Just do:
for i, key in ipairs(array) do
print(backpack);
end;
printing(backpacks[key]) -- finds the value associated with the name of that backpack, which is why it is returning the index.