GridPack - Create Grid/Tetris Style Inventories

The single slots have an .ChangedItem signal, you can use that to detect if an item is in the singleslot and then if there is, you can get the item by using SingleSlotName.Item(.Metadata.Name or whatever) and then you can do whatever you want to get the tool into the player backpack.

You’ll have to store the item names inside the Item metadata though. You can even store the tool itself in the metadata!

1 Like

Remote Events?

> > > > >

1 Like

How would i add an item with the example code ?

Thanks for your reply! Do you have a rbxl example of this? If not thanks so much for your help :slight_smile:

Finnaly im can replay, so im did this first you need make some itemdata module whre you store all info like image names etc. By this you can do functional by scanning player backpack and by this you can add item to grid ass same name of tool, best way im think is get unique tool id and name so items can be one of one kind . If you got that you can make some remote to use in like single slots by equip tool form roblox funcitons. For me now works, when im give or pickup tool script detec that and gives to grid item.

And there is whats is looks like + saving data new thing im figured out

1 Like

So my approach would be storing a list of values inside of a player then the server reads that and puts the tools with the corresponding name value into the backpack

Would this work too?

A problem I’ve found with this is SingleSlots don’t work…

Maby im not profesionlay scripter, im have connectec it to normal player bakpack hwere you store tools and Itemsdata module for me loks like this (single slots you ned aadd fuctions to use it :stuck_out_tongue: )

Idk wchat you want achive in final vesrion
here example code im use

"
local ItemsData = {}

ItemsData.Items = {
{
id = “15132722044”, – id image
name = “M4A1”, – tool name
description = " M4A1",
Type = “Rifle”,
value = 1200,
size = Vector2.new(4, 2),
position = Vector2.new(0, 0),
},
{
id = “18290801994”,
name = “AK47”,
description = " AK47",
Type = “Rifle”,
value = 1300,
size = Vector2.new(7, 3),
position = Vector2.new(4, 0),
},

function ItemsData.getItemById(itemId)
for _, item in pairs(ItemsData.Items) do
if item.id == itemId then
return item
end
end
return nil
end

function ItemsData.getItemByName(itemName)
for _, item in pairs(ItemsData.Items) do
if item.name == itemName then
return item
end
end
return nil -
end

function ItemsData.getAllItems()
return ItemsData.Items
end

return ItemsData

"

item code
"
local item = GridPack.createItem({
Position = position,
Rotation = rotation,
Size = itemData.size,
Assets = {
Item = createItemCanvasGroup(“http://www.roblox.com/asset/?id=” … itemData.id, itemData.name),
},
Metadata = {
Name = itemData.name,
Description = itemData.description,
Type = itemData.Type,
Value = itemData.value,
},
"

Im have saved rbx file wich im can shere with you privatly, but yeah is in my laungage and had manny problems and bugs etc so im trashed it out , but works equiping in singleslot if you need example

there is my discord: xxadranxxvip

Thank you so much. We’ll talk more from there

I’ve sent you a request, have you received it?

Yea im look it on when im back home on pc

How can you add a viewport image to the items? I cant figure it out

1 Like

Does this support dynamic resolutions and mobile?

Sorry, I have a question. Did you manage to change the image of the item ? Did you place this line <YOUR_ITEM>.ItemElement.Image.Image = “rbxassetid://<YOUR_ID>”
inside the myFirstItem definition ? local myFirstItem = GridPack.createItem({…}

" All items have a read-only property called .ItemElement which is set to the item’s GuiObject, so if you are using the default item asset you would do <YOUR_ITEM>.ItemElement.Image.Image = "rbxassetid://<YOUR_ID>" to change the image."

Sorry, has this changed meanwhile ? Checking the documentation, I cannot see any “ItemElement” or “Image” function.

Script makes item element in roblox gui and yeah better add function like mins you can find it on this topic, becouse is easy to change etc bcosue if you change in code all items have same image gl

Is there any way to keep the gridslot the same size regardless of it’s parent frame size?

Thanks for this amazing resource! Anyways, i found an issue where if you drag an item into an inventory that is smaller than the item, it will freeze the item.

The two errors:

Grid:211: invalid argument #3 to ‘clamp’ (max must be greater than or equal to min)
Grid:89: attempt to index nil with ‘GroupColor3’

How to fix:

In the “Grid” module script, add replace these two lines (211 and 212)

gridPosX = math.clamp(gridPosX, 0, self.GridSize.X - itemSize.X)
gridPosY = math.clamp(gridPosY, 0, self.GridSize.Y - itemSize.Y)

With:

local maxX = math.max(0, self.GridSize.X - itemSize.X)
local maxY = math.max(0, self.GridSize.Y - itemSize.Y)

gridPosX = math.clamp(gridPosX, 0, maxX)
gridPosY = math.clamp(gridPosY, 0, maxY)

In the “Grid” module script, replace these two lines (88 and 89)

local slotElement = self.SlotElements[xPosition .. ", " .. yPosition]
slotElement.GroupColor3 = highlight.Color

With:

local slotElement = self.SlotElements[xPosition .. ", " .. yPosition]
if slotElement then
	slotElement.GroupColor3 = highlight.Color
end

In “Item” module, replace these two lines (259 and 260)

local isColliding = currentItemManager:IsColliding(self, { self }, gridPos, self.PotentialRotation)
if isColliding == false then

With:

local isColliding = currentItemManager:IsColliding(self, { self }, gridPos, self.PotentialRotation)
local isInBounds = currentItemManager:IsRegionInBounds(gridPos, self.Size, self.PotentialRotation)
if not isColliding and isInBounds then

Edit: Add this function to the single slot module or else it creates a new bug.

function SingleSlot:IsRegionInBounds(position: Vector2, size: Vector2, rotation: number): boolean
	return true -- Accept all sizes/rotations
end

If you want the color to be red when the item is not in bounds, go to the “Item” module and in the _updateDraggingPosition() function add isInBounds in the if statement

local isColliding = currentItemManager:IsColliding(self, { self }, gridPos, self.PotentialRotation)
local isInBounds = currentItemManager:IsRegionInBounds(gridPos, self.Size, self.PotentialRotation)
if isColliding or not isInBounds then
	self._highlight.Color = Color3.new(1, 0, 0)
else
	self._highlight.Color = Color3.new(1, 1, 1)
end

I don’t know if this is exactly what you need it, but i did it this way:

local inventoryGridSize = Vector2.new(10, 5)
local backpackGridSize = Vector2.new(15, 10)

SLOT_SCREEN_SCALE = 0.037

local function GetInventoryFrame(frame: Frame, gridSize: Vector2): Frame
	local slotScaleY = SLOT_SCREEN_SCALE
	local slotScaleX = SLOT_SCREEN_SCALE * (9 / 16) * (workspace.CurrentCamera.ViewportSize.X / workspace.CurrentCamera.ViewportSize.Y)
	-- This keeps slots square even on stretched screens

	local totalSize = UDim2.fromScale(
		slotScaleX * gridSize.X,
		slotScaleY * gridSize.Y
	)

	frame.Size = totalSize
	frame.UIAspectRatioConstraint.AspectRatio = gridSize.X / gridSize.Y
	frame.Visible = true
	return frame
end


local Inventory = GridPack.createGrid({
	Parent = GetInventoryFrame(InventoryFrame, inventoryGridSize),
	Visible = true,
	SlotAspectRatio = 1,

	AnchorPoint = Vector2.new(0, 0.5),
	Position = UDim2.fromScale(0, 0.5),
	Size = UDim2.fromScale(1, 1),
	GridSize = inventoryGridSize
})
Inventory:ConnectTransferLink(TransferLink)

local Backpack = GridPack.createGrid({
	Parent = GetInventoryFrame(BackpackFrame, backpackGridSize),
	Visible = true,
	SlotAspectRatio = 1,

	AnchorPoint = Vector2.new(0, 0.5),
	Position = UDim2.fromScale(0, 0.5),
	Size = UDim2.fromScale(1, 1),
	GridSize = backpackGridSize
})
Backpack:ConnectTransferLink(TransferLink)