Item in custom inventory not snapping to frame correctly

I’m attempting to make a Tetris styled inventory, but I’m stuck on moving to other inventory slots. Any help would be great.

Move code:

	ItemBox.DragBegin:Connect(function()
		Dragging = true
		
		for i, v in pairs(script.Parent.Inventory.PreSliderFrame.SliderFrame:GetChildren()) do
			if v:IsA("Frame") then
				v.MouseEnter:Connect(function() -- There's probably a better way to do this but I'm not sure.
					if Dragging then
						BoxDraggedOn = v
						
					end
				end)
			end
		end

	end)
	
	ItemBox.DragStopped:Connect(function()
		Dragging = false
		
		print(BoxDraggedOn)
		
		ItemBox.Position = UDim2.new(0, BoxDraggedOn.AbsolutePosition.X, 0, BoxDraggedOn.AbsolutePosition.Y)
		
	end)

Seems to me you’re having a Gui Inset problem, try decreasing/increasing the position by 36 pixels on the Y axis

ItemBox.Position = UDim2.new(0, BoxDraggedOn.AbsolutePosition.X, 0, BoxDraggedOn.AbsolutePosition.Y - 36)
-- If it offsets even more then +36

Yes, GuiObject.MouseEnter isn’t very consistent and it is fired even if there’s another GuiObject on top.
You should use GuiObject.InputChanged with UserInputType of MouseMovement and use PlayerGui:GetGuiObjectsAtPosition(x, y) to check if there’s any GuiObject on top

1 Like

When I rotate it sideways, it messes up again. Is there something I can do about this?

image
image

Can you provide the code you used to make it rotate, I can’t really imagine what’s going on here

Oh, yes, sorry.

UserInputService.InputBegan:Connect(function(Input, IsTyping)
	if Input.KeyCode == Enum.KeyCode.R and IsTyping ~= true and Dragging == true then
		ItemBox.Rotation += 90
		
	end
end)

Was the box in this position?
image
And what is the anchor point of it?

The anchor point is 0. And I see that the problem is that I don’t have it changed, but I’m really not sure how to use anchor points.

I see, then you need to offset the anchor point by this much (the blue line)
image
Since Anchor Point uses scale instead of offset, you will have to convert the absolute position to scale

Anchor point is like the pivot of your GuiObject. I’m not really good at explaining so you should check out the documentation

ItemBox.Position = UDim2.new(0, BoxDraggedOn.AbsolutePosition.X, 0, BoxDraggedOn.AbsolutePosition.Y - 36)

Also it’s better if you convert this position from Offset into Scale, otherwise when the UI changes in size or the player screen resolution changes it’d look out of place

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