AbsolutePosition bug

I have encountered an issue on the ImageButton not matching it’s AbsolutePosition.


The white frames are an indicator actually where is the ImageButton based on its AbsolutePosition.
And the translucent black frames are where the actual ImageButton are.

This is a problem when I wanted to know if what button is the cursor on.
image
This is when i drag to the slot number 2.

Extra info:
image

function get_button_from_position(pos: Vector2): ImageButton?
	for _, button in (inventorySlots:GetChildren()):: {ImageButton} do
		if not button:IsA("ImageButton") then
			continue
		end

		-- Calculate the bounding box of the button
		local p1 = button.AbsolutePosition -- Top-left corner
		local p2 = p1 + button.AbsoluteSize -- Bottom-right corner

		-- Check if the position is within the bounding box
		if (pos.X >= p1.X) and (pos.X <= p2.X) and (pos.Y >= p1.Y) and (pos.Y <= p2.Y) then
			return button;
		end
	end

	return nil
end

UIGridLayout:

local gridLayout = Instance.new("UIGridLayout")
gridLayout.CellPadding = UDim2.fromOffset(8, 8)
gridLayout.CellSize = UDim2.fromScale(0.15, 0.15)
gridLayout.FillDirectionMaxCells = 5
gridLayout.HorizontalAlignment = Enum.HorizontalAlignment.Center
gridLayout.VerticalAlignment = Enum.VerticalAlignment.Bottom
gridLayout.SortOrder = Enum.SortOrder.LayoutOrder
1 Like

Dragging video

bump…

I tested around for a bit and the issue only shows when it’s in Play Mode:
Studio Mode:


Command ran in the Command Bar: b=game.StarterGui.InventoryStorage.InventoryFrame.InventorySlots;x=b.Parent.Parent;for _, v in b:GetChildren() do if v:IsA("ImageButton") then local c = Instance.new("Frame"); c.Parent, c.Size, c.Position = x, UDim2.fromOffset(v.AbsoluteSize.X, v.AbsoluteSize.Y) , UDim2.fromOffset(v.AbsolutePosition.X, v.AbsolutePosition.Y) end end print("h")

Play Mode:


Command ran in the Command Bar: b=game.Players.DiscoDino01.PlayerGui.InventoryStorage.InventoryFrame.InventorySlots;x=b.Parent.Parent;for _, v in b:GetChildren() do if v:IsA("ImageButton") then local c = Instance.new("Frame"); c.Parent, c.Size, c.Position = x, UDim2.fromOffset(v.AbsoluteSize.X, v.AbsoluteSize.Y) , UDim2.fromOffset(v.AbsolutePosition.X, v.AbsolutePosition.Y) end end print("h")

Heirarchy:
image

replicated the issue on a new place and the absolute position of the Frame and the ImageButton doesn’t match but the Frame UDim2 Position does match the ImageButton’s AbsolutePosition.

image

The ScreenGui 's Inset is set to None

Can someone just reply to this?

edit_solution

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