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.
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
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 )