Utilising Selected on only 1 icon

I’m trying to show what button a player has selected, however I can’t figure out a simple way to handle the stuff that’s been selected. I tried having a Selected frame, that would be parented to whatever button that was clicked. This worked great, however, if you went to a seperate tab and selected an item, the Selected template would be moved to that item.

Selecting a shirt


then selecting pants would remove the selected from the shirts tab

So I tried just giving each button its own Selected frame and turning it visible when you click on the button. However, I don’t know how to then track a previous selection (so if you select a different Shirt from your previous selection, then change the selection to the new button)

You could have 1 selection frame per tab, and pick the correct one to place according to which tab has been chosen. So you’ll have a shirt selected frame, a pants selected frame, etc

You could make a selection variable, then in your button click function, do the following:

  • Disable selection frame in selection(not yet the clicked button, since we haven’t set the selection variable yet)
  • Set selection to clicked button
  • Enable selection frame in selection(we have set the selection variable, so it’s doing it to our clicked button)

The reason for which we’re storing selection as a variable is for tracking the last selection.

Hope I helped! And good luck scripting your script!

Problem with that is having a dozen different tabs + hats/hairs and other accessories can have several selected items at once

In that case I’d have a table in your script for the tabs, and record the index or a slug/identifier for each selection.

local = SelectedItems = {
    hat = nil,
    shirt = nil,
}

function updateSelection( tab, index )
    SelectedItems[ tab ] = index
end

When you switch between tabs, you can then reposition the single selected frame to match the button for the selected index.

function showTab( tab )
    -- show your buttons
    local index = SelectedItems[ tab ]
    local buttonWithIndex = nil
    for _, button in ipairs( ButtonFrame:GetChildren() ) do
        -- if not using LayoutOrder, switch to whatever
        -- else you can use to identify the different options
        if button.LayoutOrder == index then
            buttonWithIndex = button
            break
        end
    end
    SelectionFrame.Position = buttonWithIndex.Position
end

In your button click function:

button.Activated:Connect( function()
    updateSelection( currentTab, button.LayoutOrder )
end )