wait()
local plr = game.Players.LocalPlayer
local inv = plr.minventory -- gets the inventory items in the inventory, note i'm using DataStore to save the inventory.
for i, v in pairs(inv:GetChildren()) do
if v:IsA('IntValue') then
if v.Value > 0 then
frame = script.Item:Clone()
frame.Parent = script.Parent.materialtab
frame.Name = 'Item'..i
frame.amount.Text = v.Value
frame.name.Text = v.Name
frame.Position = UDim2.new(i/10 + i/100 + 0.01, 0, 0.05, 0)-- this is the position of the item, now how would I make it so it's in order, Copper is the 6th item in the table, and always goes on the 6th slot, even if it's the only item in the inventory.
frame.Visible = true
end
end
end
-- How would I make it so if copper was the only item in the inventory, it goes to slot 1 instead of slot 6
✓ ANSWER ACCEPTED
How do you make this inventory script organize the items itself?
1 answer
✓ Accepted answer
Track your own iterations
wait()
local plr = game.Players.LocalPlayer
local inv = plr.minventory
local i = 0; -- The initial state of it
for _, v in pairs(inv:GetChildren()) do -- Ignore the iteration count for this
if v:IsA('IntValue') then
if v.Value > 0 then
i = i + 1; -- New iteration? Count it!
frame = script.Item:Clone()
frame.Parent = script.Parent.materialtab
frame.Name = 'Item'..i
frame.amount.Text = v.Value
frame.name.Text = v.Name
frame.Position = UDim2.new(i/10 + i/100 + 0.01, 0, 0.05, 0)
frame.Visible = true
end
end
end
This discussion is preserved as it was. New answers, comments, and votes are closed.
