--Updates the current selected frame.

local function UpdateActiveButton()
	local ActiveGroup = GetActiveGroup()
	
	--Reset the last frame if it the group has changed.
	if LastActiveGroup ~= ActiveGroup then
		LastActiveGroup = ActiveGroup
		LastFrame = nil
	end
	
	--Return if a controller isn't connected.
	if ControllerConnected() == false then
		return
	end
	
	--Set the frame if a group exiszts.
	if ActiveGroup then
		if not LastFrame then
			LastFrame = ActiveGroup:GetFirstFrame()
		end
		if LastFrame and not LastFrame:IsDescendantOf(game.Players) then
			LastFrame = nil
		end
		
		local CurrentSelectedObject = GuiService.SelectedObject
		if not CurrentSelectedObject or not ActiveGroup:FrameInGroup(CurrentSelectedObject) then
			GuiService.SelectedObject = LastFrame
		else
			LastFrame = CurrentSelectedObject
		end
	else
		GuiService.SelectedObject = nil
	end
end
