In a game called Rogue Lineage, it uses a custom backpack. What’s special about this specific custom backpack, is that the slots of the inventory save. For example, if you put Tool1 in slot 1, Tool3 in slot 2, and Tool2 in slot 3, it will save in that exact order. Does anyone know of a way to recreate this feature with a custom backpack?
2 Likes
I think they used tables to do that (correct me if I’m wrong).
How do you think they utilized tables for this feature?
I think every time they put a tool in a slot, they assign that tool, for example if tool1 is in slot2 then they insert the tool into index 2 (again correct me if I’m wrong).
You can just do
local Tools = {
}
for i,v in ipairs(tools) do
table.insert(Tools, {ToolSlot = SlotHere, ToolName = NameHere})
end
So saving I would be the index of the tools and ipairs for counting up from 1 to 2, 3,4, etc…
2 Likes
If you need a "dictionary table"
EX1.
local itemsToSave = {Slot1 = "tool1", Slot2 = "tool2"}
itemsToSave.Slot1 --slot1
itemsToSave.Slot2 --slot2
EX2.
local itemsToSave = {["Slot1"] = "tool1", ["Slot2"] = "tool2"}
itemsToSave["Slot1"] --slot1
itemsToSave["Slot2"] --slot2
You can save the table to the datastore like so
local customBackpack = player.CustomBackpack -- some folder within player object
--Grab all item names from the players custom backpack
local items = customBackpack:GetChildren()
local itemsToSave = {}
for i = 1, #items do
local item = items[i]
itemsToSave["Slot"..i] = item.Name
end
local success = pcall(function()
ds:SetAsync("CustomBackpack_"..player.UserId, itemsToSave)
end)
if(success) then
print("Saved items for " .. player.Name)
else
warn("Could not save items for " .. player.Name)
end
Then you can grab this table from the datastore and match item names, if any names match then you clone them to the players custom backpack
local success, data = pcall(function()
return ds:GetAsync("CustomBackpack_" .. player.UserId)
end)
if(success)then
if(data) then
local items = game.ServerStorage.Items
local customBackpack = player.CustomBackpack --some folder within player object (or server)
for i,v in pairs(data) do
local slotId = i
local itemName = v
local item = items:FindFirstChild(itemName)
if(items:FindFirstChild(itemName) then
item:Clone().Parent = customBackpack
end
end
end
print("Loaded items for " .. player.Name)
else
warn("Could not grab backpack data for " .. player.Name)
end
6 Likes
You could make a string value in each of the boxes you wan’t and then just, like if sword is in slot1 then save the slot as it is a sword in slot1. And make like:
local Slot1 = script.Parent.Slot1
local String = Slot1.String
local Tool = game.ReplicatedStorage.Sword
if String.Value == Tool.Name then do
print("Slot1:"..Tool.Name)
-- save the data
end)
2 Likes