Custom backpack and inventory system?

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:
image

Along with the backpack (I don’t want a tool tip system, if you’re wondering):

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!

11 Likes

Wait a minute… one of these things is not like the others. Are you sure that you don’t want to support the most used platform?

The backback is 2000 lines long because there is legitimately 2000 lines worth of complexity to make a robust backback that handles all the edge cases on all the platforms. Don’t forget this in your implementation challenge here, you won’t have to write 2000 lines if you cut some stuff like VR out, but you’ll still have to write pretty close to that once all is said and done.

I would take another shot at working off of the existing backpack code. Learning how to take an existing complex system and make it do something new is a really valuable skill to build, because that’s what you’ll spend most of your time doing in the workforce if you end up doing programming as a job. Start really small with your changes to get a foothold and then build up from there as you build understanding of how the code is working.

2 Likes

Thanks for the recommendation, but I refuse to make support for this platform, as the game I am making a backpack for, is a closed community one. A passion project, so to speak. It’s not intended to make profit.

1 Like

If you’re backpack doesn’t function with a said platform then remove the platforms access to play the game.

However, if you would prefer to add mobile support, then you would have to code to support it. I understand not supporting VR and Xbox.

1 Like

When I wrote my own backpack system, I utilized num keys. You can override those keys based on the platform.

Instead of supporting everything out the box, it may be far more beneficial if you test & implement your game on one platform and see where that takes you. Sometimes writing extra code for no reason is actually not in the best interest of an already bloated codebase.

Just my two-sense. Best of luck!

2 Likes