Grid Inventory Help

Im looking on how I can make a drag and drop feature, right now its pretty much nothing and I want to know how I can make

it lock on to the frames if it fits onto the area based on its size

2 Likes

What you can probably do is have a local script that will gather all of those little boxes. Then you can see if the mouse has entered inside one of the boxes by using MouseEnter and MouseLeave. If the player lets go of the GUI, you can then see what slot the player wants to put the gui in and insert that GUI into there or change it. Depends on what you want.

Feel free to ask me any questions! I will answer the best I can

1 Like

Okay butttt uhh how do I make sure the frame will be in that specific spot? like lock on it if the player drops it in the area, do I use a matrix? if that makes sence

1 Like

What you can do is temporarily save the slot. You can check if the player is even hovering over the slot by seeing if the temporary save is not nil.

Do something like this:

local slotSelected = nil

for i, slot in pairs(script.Parent.MainFrame:GetChildren()) do
	if slot.ClassName == "Frame" then
		slot.MouseEnter:Connect(function()
			slotSelected = slot
			print(slot)
		end)
		
		slot.MouseLeave:Connect(function()
			if slotSelected == slot then
				slotSelected = nil
			end
		end)
	end
end

This is a local script

What it does is saves the Instance of the slot. This is to be able to put the item in the slot the player wants to put it in. If the player is not hovering over a slot, then the value is set to nil. If they are, then the value is the slot.

Change the script to adapt to yours. Feel free to ask me any more questions if you are confused or something is wrong with the script

1 Like

i hope you realized you single handedly saved 200+ people trying to make basic grid inventorys. Would be cool if you could give a tutorial on how to make grid inventories that take multiple boxes.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.