GUI sizes not setting properly

So I’m trying to make a GUI where if you click a button, a textlabel that says “Equipped” will appear on it to indicate that it’s equipped. But for some reason, It doesn’t set the position properly. Here’s the code:

local player = game.Players.LocalPlayer
local armoryGUI = player.PlayerGui.ArmoryGui
local gadgetsFrame = armoryGUI.InventoryFrame.GadgetsFrame

gadgetsFrame.ChildAdded:Connect(function(button)
	if button:IsA("ImageButton") then
		button.MouseButton1Click:Connect(function()
			local gadget = button.Name
			local armoryGUI = player.PlayerGui.ArmoryGui
			local inventoryFrame = armoryGUI.InventoryFrame
			local equippedLabel = inventoryFrame:FindFirstChild("EquippedLabel") or inventoryFrame.GadgetsFrame:FindFirstChild("EquippedLabel")
			print(player.Name.." equipped gadget "..button.Name)
			equippedLabel.Parent = inventoryFrame
                            equippedLabel.Size = button.Size
			equippedLabel.Position = button.Position
			equippedLabel.Visible = true
			
			gadgetsFrame.GadgetEquipped:FireServer(button)
		end)
	end
end)

And here’s a screenshot of the problem:


I haven’t been able to find a solution for the past week, any help would be greatly appreciated.

Is button the bigger square box or is it the rectangular shape? I’m asking as it seems to be taking the position of that rectangular box instead of the square

The square box with the picture of a ball inside of it.

do you want the word equipped to be more centered?

I want the EquippedLabel to match the size and position of the square with a rock in it. For some reason it’s not doing that.

Instead of moving it with a script you place it where and how you want and just change visibility. could that work for you. like when you equip it makes the word equipped visible and when you equip something else it makes what’s equipped not visible and what your equipping visible. sorry if explanation is bad.

Sadly that’s not going to work since there are going to be multiple buttons, and scripting the position and size seems to be the only way to do this.

Are you using any sort of UI layout?

Yeah, I’m using UIGrid. I tried to set the size to the CellPaddingSize, but that doesn’t work either.

Okay so I was testing stuff out, so see if this works. Your CellSize will need to use scale, and so will your equippedLabel. Also, I’m not sure exactly how your frames are working, but when testing I had my frame be the whole cell, and then parented the “Label” to that frame.

equippedLabel.Position = UDim2.new(UIGridLayout.CellSize.X.Scale/2, 0, UIGridLayout.CellSize.Y.Scale/2, 0)

Sadly it still doesn’t seem to work.

I found out the solution! Basically instead of setting the EquippedLabel position, I parented it to the ImageButton and resized it so it could move with it, and made it visible if that button was clicked.