Inventory Script Help

I am trying to make a Inventory System that is clean looking and is simple to script and add stuff more in the future.

The script works but moves the ItemButtons to the next spots that are in line next and not keeping them in the same spot.

Ex: (ItemButton = spot1 otherItemButton = spot2) the ItemButton will got to spot 3 and otherItemButton will go to spot4.

I am waning the ItemButton not to move to the next spot.

How do I fix the script so that it works for all the ItemButtons and I can equip and re-equip them as many times as I want?

-- Local script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StorageEvent = ReplicatedStorage:WaitForChild("StorageEvent")
local Template = script.Template
local StorageFrame = script.Parent.StorageFrame
local MainFrame = StorageFrame.MainFrame
local InfoFrame = StorageFrame.InfoFrame

local currentSpotIndex = 1

-- CONNECT TO THE CLIENT EVENT FOR STORAGE UPDATES
StorageEvent.OnClientEvent:Connect(function(ItemName, Value)
	if Value then
		-- CREATE OR FIND THE BUTTON FOR THE ITEM
		local ItemButton = MainFrame:FindFirstChild(ItemName) or Template:Clone()
		ItemButton.Name = ItemName

		-- GET THE CURRENT SPOT FOR THE ITEM
		local currentSpot = StorageFrame.SpotFrames["Spot" .. currentSpotIndex]
		ItemButton.Parent = currentSpot
		currentSpotIndex = currentSpotIndex + 1

		-- WRAP AROUND IF INDEX EXCEEDS THE NUMBER OF SPOTFRAMES
		if currentSpotIndex > #StorageFrame.SpotFrames:GetChildren() then
			currentSpotIndex = 1
		end

		-- HANDLE CLICK EVENT ON ITEM BUTTON
		ItemButton.MouseButton1Click:Connect(function()
			local nameTextLabel = InfoFrame.NameTextLabel
			local equipButton = InfoFrame.EquipButton

			-- TOGGLE VISIBILITY OF CLOSE BUTTONS
			StorageFrame.CloseTextButton.Visible = false
			StorageFrame.CloseTextButtonB.Visible = true

			-- SET ITEM NAME IN INFOFRAME
			nameTextLabel.Text = ItemButton.Name
			InfoFrame.Visible = true

			-- HANDLE CLICK EVENT ON EQUIP BUTTON
			equipButton.MouseButton1Click:Connect(function()
				-- DESTROY UISTROKES IN ALL ITEMBUTTONS THAT ARE IN SPOTFRAMES
				local spotFrames = StorageFrame.SpotFrames:GetChildren()

				-- FUNCTION TO CHECK AND DESTROY UISTROKE
				local function checkAndDestroyUIStroke(spotFrame)
					local itemButton = spotFrame:FindFirstChild(ItemName)
					if itemButton and itemButton:IsA("GuiButton") and itemButton:FindFirstChild("UIStroke") then
						itemButton.UIStroke:Destroy()
					end
				end

				-- CHECK AND DESTROY UISTROKE FOR EACH SPOTFRAME
				for _, spotFrame in ipairs(spotFrames) do
					checkAndDestroyUIStroke(spotFrame)
				end

				-- DESTROY EXISTING ITEM BUTTON AND UISTROKE
				local existingItemButton = MainFrame:FindFirstChild(ItemName)
				if existingItemButton then
					local existingUIStroke = existingItemButton:FindFirstChild("UIStroke")
					if existingUIStroke then
						existingUIStroke:Destroy()
					end
					existingItemButton:Destroy()
					return
				end

				-- CREATE NEW UISTROKE, MOVE ITEM TO MAINFRAME, AND HIDE INFOFRAME
				local newUIStroke = script.UIStroke:Clone()
				newUIStroke.Parent = ItemButton
				ItemButton:Clone().Parent = MainFrame
				
				InfoFrame.Visible = false
				StorageFrame.CloseTextButton.Visible = true
				StorageFrame.CloseTextButtonB.Visible = false
			end)
		end)
	end
end)```

you could maybe try changing the list’s order or the button’s zindex