Hello. I am making a backpack system for my game, and I plan for it to be identical to the roblox CoreGui backpack. I have looked into the source code for this, but the module script is over 2000 lines long, along with other lines of code that are completely unless for me, like VR, Mobile, and Xbox support, along with multiple references of CoreGui. I have tried to just suck it up and edit it over the course of 2 hours, but with no luck.
The best reference I could offer at the moment this the backpack shown in this game.
If you are not able to play, I will show you the hotbar:
Along with the backpack (I don’t want a tool tip system, if you’re wondering):
https://gyazo.com/6f053c792693b1cbf5f04cceac5ba043
Here’s what I’ve done so far, although the backpack is a bit glitchy, the buttons are smushed against each other, and you can only click the button to use that tool as of yet.
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
local keys = {
[Enum.KeyCode.One] = "1",
[Enum.KeyCode.Two] = "2",
}
function createToolSlot(index, buttomName, tool)
if index > 10 then
-- make inventory slot
return
end
local newSlot = script.Slot:Clone()
newSlot.Name = index < 10 and index or 0
newSlot.Text = buttomName
newSlot.Index.Text = index < 10 and index or 0
newSlot.Tool.Value = tool
newSlot.Position = UDim2.new(1 + (index > 1 and (index / 10) * 4 or 0), 0, 0, 0)
newSlot.MouseButton1Click:Connect(function()
humanoid:UnequipTools()
if selected ~= newSlot then
if selected ~= nil then
selected.BorderSizePixel = 0
end
selected = newSlot
newSlot.BorderSizePixel = 3
humanoid:EquipTool(newSlot.Tool.Value)
else
selected = nil
newSlot.BorderSizePixel = 0
end
end)
newSlot.Parent = mainFrame
end
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed or UserInputService:GetFocusedTextBox() then
return
end
if input.KeyCode == Enum.KeyCode.Backquote then
inventoryFrame.Visible = not inventoryFrame.Visible
container.Visible = not container.Visible
end
-- if input.KeyCode == Enum.KeyCode.Equals then
-- StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
-- mainFrame.Visible = true
-- end
end)
local children = backpack:GetChildren()
for i = 1, #children do
local child = children[i]
if child:IsA("Tool") then
createToolSlot((#mainFrame:GetChildren()) + 1, child.Name, child)
end
end
I could list what I want to do here:
- Make new tool slots for every tool that is currently in the backpack
- These slots can be clicked on to select a tool
- The slots’s index can be pressed by keybaord to select a tool
- They can be dragged around to different slots, and into the inventory
- Slot and inventory interaction
Mostly, it’s really just making the backpack similar to the default one. Thank you for reading!