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